mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
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:
@@ -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
|
||||
* });
|
||||
* }
|
||||
* }
|
||||
|
||||
Reference in New Issue
Block a user