Created
October 27, 2017 16:17
-
-
Save chyngyz/8bb4040b4fd9aceb1b5e8e321b1499b5 to your computer and use it in GitHub Desktop.
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
import { DOCUMENT } from '@angular/platform-browser'; | |
import { Inject, Injectable } from '@angular/core'; | |
@Injectable() | |
export class AppReadyService { | |
private doc: Document; | |
private isAppReady: boolean; | |
constructor(@Inject(DOCUMENT) doc: any) { | |
this.doc = doc; | |
this.isAppReady = false; | |
} | |
public trigger(): void { | |
if (this.isAppReady) { | |
return; | |
} | |
const bubbles = true; | |
const cancelable = false; | |
this.doc.dispatchEvent(this.createEvent('appready', bubbles, cancelable)); | |
this.isAppReady = true; | |
} | |
private createEvent(eventType: string, bubbles: boolean, cancelable: boolean): Event { | |
let customEvent: any; | |
// IE Fallback | |
try { | |
customEvent = new CustomEvent( | |
eventType, | |
{ | |
bubbles: bubbles, | |
cancelable: cancelable | |
} | |
); | |
} catch (error) { | |
customEvent = this.doc.createEvent('appready'); | |
customEvent.initCustomEvent(eventType, bubbles, cancelable); | |
} | |
return ( customEvent ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
На странице где бутстрапится Ангуляр