I am learning angular and i got confuse in these observable, observer and subscribe thing. So please explain.
Here is a simple visual to see the difference:
As seen above ... an Observable is a stream of events or data. They are often returned from Angular methods, such as the http.get
and the myinputBox.valueChanges
.
Subscribing "kicks off" the observable stream. Without a subscribe (or an async pipe) the stream won't start emitting values. It's similar to subscribing to a newspaper or magazine ... you won't start getting them until you subscribe.
The subscribe method takes in an observer. An observer has three methods:
The method to process each time an item is emitted from the observable.
The method to process any error that occurs.
The method to clean up anything when the observer completes. This last one is seldom used when working with Angular's observables.
Hope this helps.
(And I agree ... trying to see the forest through the trees of the docs is quite a challenge. I understand they are working to improve them.)