Javascript Angular 2 CLI-第三方JS插件延迟加载

Javascript Angular 2 CLI-第三方JS插件延迟加载,javascript,angularjs,angular,lazy-loading,angular-cli,Javascript,Angularjs,Angular,Lazy Loading,Angular Cli,我在Angular 1中使用过这个,有没有类似的插件可以在Angular 2中使用?我想在Angular 2项目中包括第三方Javascript按需插件(延迟加载)。到目前为止没有成功 我目前正在研究。我已经尝试在angularcli.json文件中包括jquery,这似乎很有效。但我认为这是全球负荷 "styles": [ "styles.css", "../node_modules/bootstrap/dist/css/bootstrap.css" ], "scr

我在Angular 1中使用过这个,有没有类似的插件可以在Angular 2中使用?我想在Angular 2项目中包括第三方Javascript按需插件(延迟加载)。到目前为止没有成功

我目前正在研究。我已经尝试在
angularcli.json
文件中包括jquery,这似乎很有效。但我认为这是全球负荷

  "styles": [
    "styles.css",
    "../node_modules/bootstrap/dist/css/bootstrap.css"
  ],
  "scripts": [
    "../node_modules/jquery/dist/jquery.js"
  ],
假设我想要一个页面,页面中有
WOW.js
插件。我应该调用一个内部启动了WOW.js的组件,然后动态地包含
WOW.js
文件。怎么做


谢谢

您可以将angular-cli.json配置文件中的WOW.js文件添加到您的资产中

"assets": [
    "pathToYourPlugin/WOW.js"
  ],
然后在组件中添加脚本标记以导入库

<script src="/WOW.js"></script>


my component html模板只是整个页面的一部分。如果我把这个
放在中间而不是中间,可以吗?当然可以。建议的方法是在身体的末端。这个答案不是很实用,但它解决了您的需求。
没有导入。我确认可以在这里看到脚本
http://localhost:4200/assets/wow.js
。当我使用dev工具检查元素时,
标记从html中消失。请帮忙。谢谢,您不应该通过angular添加它,而是通过模板或内部html添加它。是的,我将它放在模板
dashboard.component.html
文件中<代码>@Component({selector:'app dashboard',templateUrl:'./dashboard.Component.html'})