As requested by @katspaugh
In your particular case, there is no need to manually cancel the subscription, as this is an Async job.
Check out the source code for AsyncPipe. For brevity, I send the appropriate code
class AsyncPipe implements PipeTransform, OnDestroy {
As you can see, the Async channel implements OnDestroy, and when it is destroyed, it checks to see if there is any subscription and deletes it.
You would invent the wheel in this particular case (sorry for repeating yourself). This does not mean that you cannot / should not unsubscribe yourself in any other case, like the one you referred to. In this case, the user passes the Observable between the components to inform them, so itβs good practice to manually cancel the subscription.
I do not know if the framework will be able to detect any live subscriptions and automatically unsubscribe them when the Components are destroyed, which will require more study.
Hope this clarifies a bit about the Async pipe.
Eric Martinez Dec 27 '15 at 18:14 2015-12-27 18:14
source share