It is possible to get this information from the Angular Router
.
As of version @angular/core: 7.2.0
.
html:
<router-outlet name="myOutlet"></router-outlet>
ts of any component file:
export class MyComponent {
constructor(
router: Router
) {}
ngOnInit(): void {
const myOutletIsActive: Observable<boolean> = this.router.events.pipe(
filter((event: RouterEvent) => event instanceof NavigationEnd),
map(() => this.router.getCurrentNavigation()
.extractedUrl.root.children.primary.children.myOutlet !== undefined)
);
myOutletIsActive.subscribe(isActive => console.log('isActive', isActive));
}
}
The advantage is that you can retrieve the state of every outlet from every component of your app.