Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

return observable from function angular

1. Better practise is to use Observable:

import { catchError } from 'rxjs/operators';
import { throwError } from 'rxjs';

bbb() {
 return this.http.get(this.url)
   .pipe(
     catchError(err => {
       console.log('err', err);
       return throwError('Something bad happened; please try again later.');
     });
}

2. And, then simply just subscribe to bbb:

import { Subscription } from 'rxjs';

testSubscription: Subscription;

ngAfterContentInit() {
    this.testSubscription = this.bbb()
      .subscribe(son => {
        console.log('son', son); // here you get the result
      });
}

3. Don't forget to unsubscribe:

ngOnDestroy() {
  this.testSubscription.unsubscribe();
}
Comment

obeservable from an object angular

//Put an object in a observable
let myObj = {name: "Maria", age: 23};
this.myObs$ = of(myObj);
Comment

display observable in html angular

 
<!--.html file-  use '|async' pipe -->
<ul class=""  scope="row" *ngFor="let aboutus of this.pageData |async " >             
		<li>{{aboutus.key}} {{aboutus.data.details}} </li>                               
 </ul>
Comment

what is observable in angular

Observable in Angular is a feature that provides support 
for delivering messages between different parts of your single-page application.
This feature is frequently used in Angular because it is responsible 
for handling multiple values, asynchronous programming in Javascript, 
  and also event handling processes.
Comment

PREVIOUS NEXT
Code Example
Javascript :: one signal api to send notification 
Javascript :: json concat 
Javascript :: Animated Sticky Header 
Javascript :: angular mouseenter 
Javascript :: display toastr info 
Javascript :: cheapest node js hosting 
Javascript :: jsdoc object destructuring 
Javascript :: dynamic for loop react 
Javascript :: promise javascript 
Javascript :: javascript dom after a element 
Javascript :: what is the slice method in javascript 
Javascript :: javascript addeventlistener click only works once 
Javascript :: change app name in react native android 
Javascript :: logical operators in javascript 
Javascript :: react native share link 
Javascript :: what is package.json 
Javascript :: dynamic input fields with radio button 
Javascript :: make image onclick in vuejs 
Javascript :: paper in material ui 
Javascript :: password generator 
Javascript :: access index of array javascript 
Javascript :: inline styling react 
Javascript :: remove string from outside array javascript 
Javascript :: angular reference element 
Javascript :: javascript recursion 
Javascript :: mongoose node js 
Javascript :: schema knex.js 
Javascript :: form serialize object javascript 
Javascript :: Finding Value of Promise With Then Syntax 
Javascript :: longest string 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =