Last active
July 26, 2017 08:02
-
-
Save ValentinFunk/ad6f60182cbf29451c28d798a0468eed to your computer and use it in GitHub Desktop.
Angular2 Router Loading Screen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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