Skip to content

Instantly share code, notes, and snippets.

@etiennetalbot
Last active December 13, 2018 16:04
Show Gist options
  • Save etiennetalbot/c15b316bec36c24e0049930ea27a50cc to your computer and use it in GitHub Desktop.
Save etiennetalbot/c15b316bec36c24e0049930ea27a50cc to your computer and use it in GitHub Desktop.
Angular Resolver - NavigationStart and NavigationEnd
import { Component, OnInit } from '@angular/core';
import { filter } from 'rxjs/operators';
import { NavigationEnd, NavigationStart, Router } from '@angular/router';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
})
export class AppComponent implements OnInit {
isLoadingRoute: boolean = false;
constructor(
private router: Router,
) {}
ngOnInit(): void {
this.router.events.pipe(
filter(e => e instanceof NavigationStart)
).subscribe(() => { this.isLoadingRoute = true });
this.router.events.pipe(
filter(e => e instanceof NavigationEnd)
).subscribe(() => { this.isLoadingRoute = false });
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment