Skip to content

Instantly share code, notes, and snippets.

@chyngyz
Created October 27, 2017 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chyngyz/8bb4040b4fd9aceb1b5e8e321b1499b5 to your computer and use it in GitHub Desktop.
Save chyngyz/8bb4040b4fd9aceb1b5e8e321b1499b5 to your computer and use it in GitHub Desktop.
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 );
}
}
@chyngyz
Copy link
Author

chyngyz commented Oct 27, 2017

На странице где бутстрапится Ангуляр

<script type="text/javascript">
      document.addEventListener("appready", handleAppReady);
      function handleAppReady(event) {
        var preBootstrapContainer = document.getElementById("pre-bootstrap-container");
        var preBootstrap = document.getElementById("pre-bootstrap");
        preBootstrap.className = "loaded";
        setTimeout(
          function removeLoadingScreen() {
            preBootstrapContainer
              .parentNode
              .removeChild(preBootstrapContainer);
          }
        );
      }
    </script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment