docs: Add import line to router event example for clarification (#42935)

Without the `import {Event} from '@angular/router';`, the filter will
not work because the type is understood as the native `Event`.

Fixes #42920

PR Close #42935
This commit is contained in:
Andrew Scott 2021-07-22 12:19:44 -07:00 committed by Dylan Hunn
parent 1f6cc57812
commit a6c256fcd6
1 changed files with 4 additions and 2 deletions

View File

@ -27,12 +27,14 @@ export type NavigationTrigger = 'imperative'|'popstate'|'hashchange';
* The following code shows how a class subscribes to router events. * The following code shows how a class subscribes to router events.
* *
* ```ts * ```ts
* import {Event, RouterEvent, Router} from '@angular/router';
*
* class MyService { * class MyService {
* constructor(public router: Router, logger: Logger) { * constructor(public router: Router) {
* router.events.pipe( * router.events.pipe(
* filter((e: Event): e is RouterEvent => e instanceof RouterEvent) * filter((e: Event): e is RouterEvent => e instanceof RouterEvent)
* ).subscribe((e: RouterEvent) => { * ).subscribe((e: RouterEvent) => {
* logger.log(e.id, e.url); * // Do something
* }); * });
* } * }
* } * }