Make sure the splash screen element exists before adding an event to it

This commit is contained in:
Sercan Yemen 2018-02-05 11:29:30 +03:00
parent b0101a1f8c
commit f246fab1f4

View File

@ -15,18 +15,27 @@ export class FuseSplashScreenService
private router: Router private router: Router
) )
{ {
// Get the splash screen element
this.splashScreenEl = this.document.body.querySelector('#fuse-splash-screen'); this.splashScreenEl = this.document.body.querySelector('#fuse-splash-screen');
const hideOnLoad = this.router.events.subscribe((event) => { // If the splash screen element exists...
if ( event instanceof NavigationEnd ) if ( this.splashScreenEl )
{ {
setTimeout(() => { // Hide it on the first NavigationEnd event
this.hide(); const hideOnLoad = this.router.events.subscribe((event) => {
hideOnLoad.unsubscribe(); if ( event instanceof NavigationEnd )
}, 0); {
setTimeout(() => {
this.hide();
// Unsubscribe from this event so it
// won't get triggered again
hideOnLoad.unsubscribe();
}, 0);
}
} }
} );
); }
} }
show() show()