Skip to content

Instantly share code, notes, and snippets.

@ValentinFunk
Last active July 26, 2017 08:02
Show Gist options
  • Save ValentinFunk/ad6f60182cbf29451c28d798a0468eed to your computer and use it in GitHub Desktop.
Save ValentinFunk/ad6f60182cbf29451c28d798a0468eed to your computer and use it in GitHub Desktop.
Angular2 Router Loading Screen
export class AppComponent {
routerLoading$: Observable<boolean>;
constructor(private router: Router) {
this.routerLoading$ = this.router.events.flatMap(event => {
if (event instanceof NavigationStart) {
return [true];
}
if (event instanceof NavigationEnd ||
event instanceof NavigationCancel ||
event instanceof NavigationError) {
return [false];
}
return Observable.never();
});
}
}
// HTML
<div>
<div class="router-loading-indicator" *ngIf="routerLoading$ | async">
<spinner></spinner>
</div>
<router-outlet></router-outlet>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment