title: How to wait until component is fully loaded on Angular 2
body: <p>I need to run a script when a Component is fully loaded.  Is there a way to do that, like ajaxStart() and .ajaxStop() on jQuery?</p>
  
  <p>I am trying to add my code on ngAfterViewInit(); but sometimes the component is not fully loaded when that function is called.</p>
  
  <p>Thank you so much :)</p>
  
  <p>My code is as follows:</p>
  
  <pre><code>export class AppComponent {
      constructor(private elementRef: ElementRef) { };
      ngAfterViewInit() {
          var s = document.createElement("script");
          s.type = "text/javascript";
          s.src = "./assets/js/my-script-to-run.js";
          this.elementRef.nativeElement.appendChild(s);
      }
   }
  </code></pre>