在我的angular cli项目中,我需要引用不是节点包的外部js库.因此,它们不会位于node_modules文件夹下,因为它们不是由npm安装的.这些是松散的js文件.
>在角度cli项目结构中,我应该在哪里添加它们作为最佳
练习,以便我可以在脚本数组中添加它们
.angular-cli.json文件?
>我如何在我的打字稿文件中使用它们?
下面的链接解释了我们如何在.angular-cli.json文件的脚本数组中引用它们.但是,如果它们不是节点模块,它不会告诉外部js文件应该在angular cli项目的文件夹结构中添加到何处.
Angular Cli Webpack,How to add or bundle external js files?
解决方法
在assets文件夹中添加外部js文件,例如:assets => js => filename.js
.angular-cli.json
"scripts": [ "../src/assets/js/externalfilename.js" ]
在.angular-cli.json文件中更改后很重要.停止项目然后开始
如何在ts文件示例中使用如下:
editor.js内
<!-- assets/js/editor.js --> Editor = function() { //This is my javascript function console.log('Editor'); }
editor.js将添加.angular-cli.json
"scripts": [ "../src/assets/js/editor.js" ]
在component.ts文件中
declare var Editor: any; export class EditorComponent { }