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 :: load a component on button click react 
Javascript :: date formatting javascript 
Javascript :: js or operator 
Javascript :: new file shortcut vscode 
Javascript :: sweetalret 
Javascript :: javascript if else 
Javascript :: how to edit image tags in javascript 
Javascript :: else in javascript 
Javascript :: last element from list javascript 
Javascript :: template literals js 
Javascript :: angular get firebase firestore 
Javascript :: node red push to array 
Javascript :: rxjs sequence of api calls 
Javascript :: signup Using codegniter in ajax 
Javascript :: how to access array of objects in javascript 
Javascript :: how to firebase.database().ref push unique id in same unique id firebase 
Javascript :: code for random dom background image change 
Javascript :: action cable nuxtjs 
Javascript :: dynamic thumbnail on hover in javascript 
Javascript :: firestore save a score as a number not a string in js 
Javascript :: what does tilde (~) and caret (^) mens in package.json file 
Javascript :: how to check expo package compatibility 
Javascript :: react prototype function 
Javascript :: extract values from a column in json format python 
Javascript :: asciicinema 
Javascript :: connect react native app to local api macos 
Javascript :: what is reveal.js plugin 
Javascript :: left_field in jsgrid 
Javascript :: set drawingmode javascript 
Javascript :: css rotate3d euler angles 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =