@ -14,9 +14,12 @@ import {
Router,
} from '@angular/router';
import { filter } from 'rxjs/operators';
import { inject, Injectable } from '@angular/core';
@Injectable ()
class SomeService {
private router = inject(Router);
navigationFinish$ = this.router.events.pipe(
filter(
event =>
@ -26,8 +29,6 @@ class SomeService {
),
);
/* Observable< Event > */
constructor(private router: Router) {}
}
```
@ -38,10 +39,10 @@ import { RouterEvents } from '@abp/ng.core';
@Injectable ()
class SomeService {
private routerEvents = inject(RouterEvents);
navigationFinish$ = this.routerEvents.getNavigationEvents('End', 'Error', 'Cancel');
/* Observable< NavigationCancel | NavigationEnd | NavigationError > */
constructor(private routerEvents: RouterEvents) {}
}
```
@ -62,6 +63,8 @@ import { mapTo } from 'rxjs/operators';
@Injectable ()
class SomeService {
private routerEvents = inject(RouterEvents);
navigationStart$ = this.routerEvents.getNavigationEvents('Start');
/* Observable< NavigationStart > */
@ -73,8 +76,6 @@ class SomeService {
this.navigationFinish$.pipe(mapTo(false)),
);
/* Observable< boolean > */
constructor(private routerEvents: RouterEvents) {}
}
```
@ -88,6 +89,8 @@ import { map } from 'rxjs/operators';
@Injectable ()
class SomeService {
private routerEvents = inject(RouterEvents);
navigationEvent$ = this.routerEvents.getAllNavigationEvents();
/* Observable< NavigationCancel | NavigationEnd | NavigationError | NavigationStart > */
@ -95,8 +98,6 @@ class SomeService {
map(event => event instanceof NavigationStart),
);
/* Observable< boolean > */
constructor(private routerEvents: RouterEvents) {}
}
```
@ -127,7 +128,7 @@ class SomeService {
### How to Get Specific Router Events
You can use `getEvents` to get a stream of router events matching given event constructor s.
You can use `getEvents` to get a stream of router events matching given event classe s.
```js
import { RouterEvents } from '@abp/ng.core';
@ -135,16 +136,16 @@ import { ActivationEnd, ChildActivationEnd } from '@angular/router';
@Injectable ()
class SomeService {
private routerEvents = inject(RouterEvents);
moduleActivation$ = this.routerEvents.getEvents(ActivationEnd, ChildActivationEnd);
/* Observable< ActivationEnd | ChildActivationEnd > */
constructor(private routerEvents: RouterEvents) {}
}
```
### How to Get All Router Events
You can use `getEvents` to get a stream of all router events without passing any event constructor s. This is nothing different from accessing `events` property of `Router` and is added to the service just for convenience.
You can use `getEvents` to get a stream of all router events without passing any event classe s. This is nothing different from accessing `events` property of `Router` and is added to the service just for convenience.
```js
import { RouterEvents } from '@abp/ng.core';
@ -152,9 +153,9 @@ import { ActivationEnd, ChildActivationEnd } from '@angular/router';
@Injectable ()
class SomeService {
private routerEvents = inject(RouterEvents);
routerEvent$ = this.routerEvents.getAllEvents();
/* Observable< Event > */
constructor(private routerEvents: RouterEvents) {}
}
```