Posts

Showing posts from September, 2018

Working with Observable and BehaviorSubject in Angular

Image
Observable: Observable opens a continuous communication channel which can emit multiple values of data over a  period of time. Observable will not be invoked until you subscribe to it. The subscribe method has three call back functions as parameters. When ever the data is available then first callback function will be invoked. When there is an error then second callback method will be invoked. Once you call complete() from observer then third callback function will be invoked. Here is an example. Step #1:  First import necessary libraries. import { Observable } from ' rxjs ' ;   Step #2:  Declare a variable as Observable and  define Observable.  data:Observable<number>;    ngOnInit(){         this .data =  new  Observable(observer=>{          observer.next(1);          ...