Reactive programming is an asynchronous programming with data streams.
In Rxjs,Mostly they use Observable for reactive programming.
An observable is alternative to promises.So user can choose either observable or promises that depending on their needs.
It also provides many operators to work with observables.
In simple term, Observable is a stream of data.
In Rxjs,Mostly they use Observable for reactive programming.
How to create Observable in simple way?
import {Observable} from the 'rxjs'
var testobservable = Observable.Create((Observer:any)=>{
Observer.next('Hello');
Observer.next('AngularWorld');
});
Explanation of above code in simple way :
Observer is stream of events which sends notifications to Observables.
There are 3 Types of notifications are send through Observers.
1) Next
2) Error
3) Complete
The above notifications should be subscribed then only it will display in browser.
testobservable.subscribe((x:any)=>console.log(x))
Now you see 'Hello Angularworld' output in your browser console tab.
Observer receives notifications from Observable and is managed by subscriptions.
In Angular, we are often consumers or Observer of asynchronous event emitted by Observable.
Some common use cases are HTTP request and HTTP Routing parameters
The Notification class is emitted by Observable stream.Notification are pushed through Observable to all its observers.
The types of notifications are Next(),Error() and complete().