我需要在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);
}
}