Angular 2 observable subscription not triggering

The same service instance isn’t being shared across your App and Home components because you have listed SidenavService as a provider for both. When you define service provider in the providers entry of a Component decorator, that service is then available to that component and all of its children as a singleton, meaning the same … Read more

What is observable, observer and subscribe in angular?

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. … Read more

What does the .subscribe() function do?

The .subscribe() function is similar to the Promise.then(), .catch() and .finally() methods in jQuery, but instead of dealing with promises it deals with Observables. That means it will subscribe itself to the observable of interest (which is getTasks() in your case) and wait until it is successful and then execute the first passed callback function … Read more

Is it necessary to unsubscribe from observables created by Http methods to avoid memory leaks?

So the answer is no, you don’t. Ng2 will clean it up itself. The Http service source, from Angular’s Http XHR backend source: Notice how it runs the complete() after getting the result. This means it actually unsubscribes on completion. So you don’t need to do it yourself. Here is a test to validate: fetchFilms() … Read more

How to detect rxjs related memory leaks in Angular apps

Disclaimer: I’m the author of the tool I mention below. This can be accomplished by keeping a list where new subscriptions are added to, and removing subscriptions from this list once it is unsubscribed. The troublesome part is observing subscriptions. A straightforward way to achieve this is by monkey-patching the Observable#subscribe() method, that is, replacing … Read more