From f246fab1f4f190f954ad7ec25c2708777a05183d Mon Sep 17 00:00:00 2001 From: Sercan Yemen Date: Mon, 5 Feb 2018 11:29:30 +0300 Subject: [PATCH] Make sure the splash screen element exists before adding an event to it --- .../core/services/splash-screen.service.ts | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/app/core/services/splash-screen.service.ts b/src/app/core/services/splash-screen.service.ts index 4ac990c4..fe85cde8 100644 --- a/src/app/core/services/splash-screen.service.ts +++ b/src/app/core/services/splash-screen.service.ts @@ -15,18 +15,27 @@ export class FuseSplashScreenService private router: Router ) { + // Get the splash screen element this.splashScreenEl = this.document.body.querySelector('#fuse-splash-screen'); - const hideOnLoad = this.router.events.subscribe((event) => { - if ( event instanceof NavigationEnd ) - { - setTimeout(() => { - this.hide(); - hideOnLoad.unsubscribe(); - }, 0); + // If the splash screen element exists... + if ( this.splashScreenEl ) + { + // Hide it on the first NavigationEnd event + const hideOnLoad = this.router.events.subscribe((event) => { + if ( event instanceof NavigationEnd ) + { + setTimeout(() => { + this.hide(); + + // Unsubscribe from this event so it + // won't get triggered again + hideOnLoad.unsubscribe(); + }, 0); + } } - } - ); + ); + } } show()