March 2017
Intermediate to advanced
118 pages
2h 1m
English
To listen to events, inject the router service and subscribe to the events observable.
class MailAppCmp {
constructor(r: Router) {
r.events.subscribe(e => {
console.log("event", e);
});
}
}
For instance, let's say we want to update the title any time the user successfully navigates. An easy way to do that would be to listen to all NavigationEnd events:
class MailAppCmp {
constructor(r: Router, titleService: TitleService) {
r.events.filter(e => e instanceof NavigationEnd).subscribe(e => {
titleService.updateTitleForUrl(e.url);
});
}
}
Read now
Unlock full access