One of the best-practice principles of Angular is to always use AsyncPipe when possible and only use .subscribe() when the side effect is an absolute necessity and cannot be avoided.

What Is an Observable?

An Observable is an abstraction of an asynchronous stream of data. For example, when we look at anObservable, it represents a stream of strings that will be delivered one by one over time. TK (

But when the Observable gets modified, how do we display data? This is where we use .subscribe().

Subscribe Function

We pass the Observable around, combining it and saving it to different variables with different combinations of operators, but at the end, an Observable<T> is useless on its own. We need a way to “terminate” the Observable and extract the type T out of it. That is what .subscribe is used for: to subscribe to the resulting stream and terminate the observable. TK (

#angular #javascript #observables #programming #rxjs

Angular: Avoid the Subscribe() Method for Observables
4.60 GEEK