This way, we can call componentDestroyed as often as needed. The existing ngOnDestroy gets called by the new ngOnDestroy method. At runtime, the function componentDestroyed alters the component instance and creates a new ngOnDestroy method which in turn calls an internally created Subject. No need to create a Subject and manually call next() in ngOnDestroy. But instead of passing in a custom Subject, we only call componentDestroyed(this). The Problem export class SimpleComponent implements OnInit, OnDestroy Also, depending on the code in our subscription, we simply create bugs. If we miss to do so, we create memory leaks that are very, very hard to debug. ![]() Here, “correctly” mostly means at the right time. While this enables much richer service compositions and helps to arrange complex data flows, it puts an additional burden on us developers: We always need to correctly unsubscribe our Subscriptions. The Http service returns Observables instead of Promises (as in version 1), route parameters are queried as Observables and EventEmitter is basically an alias for Subject. Since version 2, Angular heavily relies on ReactiveX for its API. ![]() The easiest way to unsubscribe from Observables in Angular
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |