3 ms·
> Actually I think it often feels awkward to work with RxJS in Angular, especially when you use observables that are not used via the Async-Pipe, unsubscribing
by spaceribs 6y ago
> Actually I think it often feels awkward to work with RxJS in Angular, especially when you use observables that are not used via the Async-Pipe, unsubscribing for instance is annoying at best.
I agree with this sentiment, we've been waiting patiently for observable inputs for a ridiculously long time: https://github.com/angular/angular/issues/5689 https://github.com/angular/angular/issues/5689, but I do have a pretty solid pattern for dealing with subscriptions these days:
1. Create one subscription as a private member of your class: https://github.com/spaceribs/plopdown/blob/4823f5017733ee7855a9214cf7959723aa2a7bcd/apps/website/src/app/home/home.component.ts#L32 https://github.com/spaceribs/plopdown/blob/4823f5017733ee785...
2. In your OnInit, subscribe and add that to your main component subscription: https://github.com/spaceribs/plopdown/blob/4823f5017733ee7855a9214cf7959723aa2a7bcd/apps/website/src/app/home/home.component.ts#L103 https://github.com/spaceribs/plopdown/blob/4823f5017733ee785...
3. Unsubscribe from everything in your destroy method: https://github.com/spaceribs/plopdown/blob/4823f5017733ee7855a9214cf7959723aa2a7bcd/apps/website/src/app/home/home.component.ts#L122 https://github.com/spaceribs/plopdown/blob/4823f5017733ee785...