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?
router.events
you will see it is a Subject, so it has an unsubscribe method when you store the subscription.let sub = this.router.events.subscribe()
if you console.log(sub) you will see it has the unsubscribe method.subscribe()
is what gets stored insub
.