Angular — Three alternatives for unsubscribing observables at ngOnDestroy

Liu Ting Chun
4 min readDec 9, 2022

RxJS is a common library in the world of Angular. If you have been using RxJS for some time, you may have already faced the unsubscription issue. Simply put, after making a subscription, you will always need to unsubscribe at a certain point to avoid memory leaks. We want it to happen during component ngOnDestroy in most cases. However, managing these subscriptions explicitly for each component could be troublesome and painful. Here I have summarised three alternatives that could help to generalize the unsubscription logic and make…

--

--

Liu Ting Chun

Web developer from Hong Kong. Most interested in Angular and Vue. Currently working on a Nuxt.js + NestJS project.