I'm building an App using Angular + Ionic.
When I present the data in an observable in my template using the async pipe.
My understanding is that Angular automatically unsubscribe from the observable when the component is destroyed, but, if I move to another page, the ngOnDestroy event is not being fired. Does it mean that I'm not unsubscribing from the observable?
Thanks!
unsubscribe and ngOnDestroy are 2 different concepts :
unsubscribe closes an observer stream : the subscription won't listen to new eventsngOnDestroy is ran when a directive is destroyed (removed from the DOM)async pipes are automatically unsubscribing from the observables they're fed with : but that isn't because of the ngOnDestroy function.
If your function doesn't get triggered, it either means that you don't destroy your component, or that you have an issue.
If so, please provide a sandbox reproducing it, for instance on https://stackblitz.com
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With