Cover photo by Tim Swaan on Unsplash.
This article explains how to manage subscriptions in Angular components without repeating the same teardown ...
For further actions, you may consider blocking this person and/or reporting abuse
Great article! 👌
I have written a similar article that describes 5 ways to unsubscribe observables and I think you just proposed the 6th! 🚀
[4+1 ways] How to Unsubscribe from Observables in Angular like a 😎
Nikos Anifantis ・ May 26 ・ 7 min read
Good one Nikos !!
Many many thanks Madhu!
Thanks Nikos!
It’s a good idea to destroy observables using a helper class but not recommend to do this way as it causes each class or component to inherit the helper class to just destroy a subscription. If you expect a observer and want to kill it just Do pipe(take(1)) and if you expect a promise like user profile api request use.toPromise() instead of .subscribe(). I say this from experience using to helper method just cause extra code that’s not need. But great Article
I quite like npmjs.com/package/@ngneat/until-de... . I think it's worth a look. I agree though that ComponentStore is fantastic :)
Sorry I skimmed and missed the subtleties of your approach, that's really nice :)
Thank you :)
Wow, this is clever. This pattern will reduce a lot of boilerplate from my code, thanks!
Nice one !!
Cool! How about the async pipe approach also?
Yes,
async
is always a great choice for displaying Observable results on a template :)Thanks Ankita! I will :)