用一个变量接收文件路径userFunctionJS: any="../../assets/js/index.js";
ngAfterViewInit(){
// alert($('#yjfkxh').html());
if (this.userFunctionJS){
this.loadScript(this.userFunctionJS);
}else{
console.log("userFunctionJS=" + this.userFunctionJS);
}
}
loadScript(scriptUrl: string) {
return new Promise((resolve, reject) => {
console.log("loadScript:" + scriptUrl);
const scriptElement = document.createElement('script')
scriptElement.src = scriptUrl
scriptElement.onload = resolve
document.body.appendChild(scriptElement)
})
}