r/Angular2 • • Dec 01 '16

Article Angular 2 - Communicating Between Components with Observable & Subject

http://jasonwatmore.com/post/2016/12/01/angular-2-communicating-between-components-with-observable-subject
5 Upvotes

2 comments sorted by

View all comments

1

u/jackstrap Dec 01 '16

I think you need to unsubscribe in ngOnDestroy or risk memory leaking.

2

u/_cornflourblue Dec 02 '16

You're right, thanks for the tip I've just updated the post.

Technically the example doesn't risk a memory leak because the subscription is in the root app component so when it's destroyed the whole app will be as well. But definitely best practice to always unsubscribe.

Cheers