如何在不添加资产函数的情况下在angular中使用外部js



我需要在我的angular项目中使用外部js,而不需要将其添加到包含名称空间的资产folder.js中。

您可以使用from cdn包

这允许您将外部js/css添加到组件中,而无需将其添加到assets文件夹中。

从"from cdn"导入from cdn;来自CDN(["//cdn.some.com/a/a.js","//cdn.some.com/a/b.js","//cdn.some.com/a/a.ss",]).then(_=>alert("All is ready"((
1. You can create a test.js file in same component  and just use this code in your component.ts
ngOnInit() {  
this.loadJsFile(FilEPath);  
}  
public loadJsFile(url) {  
let node = document.createElement('script');  
node.src = url;  
node.type = 'text/javascript';  
document.getElementsByTagName('head')[0].appendChild(node);  
} 

最新更新