1 回答

TA貢獻(xiàn)1862條經(jīng)驗(yàn) 獲得超6個贊
要在 Angular App 完成初始化后加載外部腳本,您可以通過<script>在DOM.
loadScript() {
const scriptElement = this.document.createElement('script');
scriptElement.src = 'https://....js';
scriptElement.type = 'text/javascript';
const headElements = this.document.getElementsByTagName('head');
headElements[0].appendChild(scriptElement);
}
component constructor那么您可以在 a或您的app module constructor:中調(diào)用此方法
app.module.ts:
export class AppModule {
constructor() {
this.loadScript();
}
loadScript() {
...
}
}
more details with [this tutorial][1].
[1]: http://www.lukasjakob.com/how-to-dynamically-load-external-scripts-in-angular/
添加回答
舉報(bào)