如何等待组件在Angular 2上完全加载

时间:2016-06-27 21:03:28

标签: angularjs angular components

我需要在Component完全加载时运行脚本。有没有办法做到这一点,比如jQuery上的ajaxStart()和.ajaxStop()?

我正在尝试在ngAfterViewInit()上添加我的代码;但有时在调用该函数时组件未完全加载。

非常感谢你:)

我的代码如下:

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);
    }
 }

0 个答案:

没有答案
相关问题