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:
parent
1f6cc57812
commit
a6c256fcd6
|
@ -27,12 +27,14 @@ export type NavigationTrigger = 'imperative'|'popstate'|'hashchange';
|
|||
* The following code shows how a class subscribes to router events.
|
||||
*
|
||||
* ```ts
|
||||
* import {Event, RouterEvent, Router} from '@angular/router';
|
||||
*
|
||||
* class MyService {
|
||||
* constructor(public router: Router, logger: Logger) {
|
||||
* constructor(public router: Router) {
|
||||
* router.events.pipe(
|
||||
* filter((e: Event): e is RouterEvent => e instanceof RouterEvent)
|
||||
* ).subscribe((e: RouterEvent) => {
|
||||
* logger.log(e.id, e.url);
|
||||
* // Do something
|
||||
* });
|
||||
* }
|
||||
* }
|
||||
|
|
Loading…
Reference in New Issue