docs(router): filter the event to subscribe (#37027)

The current code will not work as the `e` will be an event,
If we try to access e.id and e.url it will throw an exception, the correct way is to use map or filter down to specific events

PR Close #37027
This commit is contained in:
Santosh Yadav 2020-05-13 00:59:11 +05:30 committed by Kara Erickson
parent 92590693e6
commit 3813f54bec

View File

@ -30,8 +30,8 @@ export type NavigationTrigger = 'imperative'|'popstate'|'hashchange';
* class MyService {
* constructor(public router: Router, logger: Logger) {
* router.events.pipe(
* filter(e => e instanceof RouterEvent)
* ).subscribe(e => {
* filter((e: Event): e is RouterEvent => e instanceof RouterEvent)
* ).subscribe((e: RouterEvent) => {
* logger.log(e.id, e.url);
* });
* }