Issue
In my ngOnInit method I am subscribing to the Router like this:
this.router.events.subscribe(
event => {
if (event instanceof NavigationEnd) this.clearMessages();
}
);
Normally, for Observables outside of the HttpClient package I call unsubscribe in the ngOnDestroy method but when I tried that here I discovered that this.router.events does not have such a method. Am I mistaken or is there something different about this Observable? Why would unsubscribe not be implemented?
Solution
I discovered that this.router.events does not have such a method
You call unsubscribe
on subscriptions, not observables. And this.router.events
is an observable, not subscription. So the following would work:
const subscription = this.router.events.subscribe(...);
subscription.unsubscribe();
Answered By - Max Koretskyi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.