gpt4 book ai didi

javascript - 在 Angular2 中添加外部库

转载 作者:太空宇宙 更新时间:2023-11-04 16:18:45 24 4
gpt4 key购买 nike

我正在开始我的 Angular2 冒险,我已经阅读了很多教程,但有一点我担心。假设我们有两种 View - 一种带有报告,另一种带有上传图像。

第一个 View 将由'ReportComponent'处理,在html模板上它将使用'Chart.js'库
第二个 View 将由'UploadMediaComponent'处理,在html模板上它将使用'Dropzone.js'

如何在 html 中包含这个 javascript 库?在大多数教程中,我读过的唯一解决方法是在index.html页面中包含两个库(这与单页面应用程序模式一致)。但另一方面 - 我们是否真的需要一次加载数百个外部库并开始加载应用程序,即使我们只需要在一个 View (一个组件)中使用它?假设我只需要在一个 View 上使用 'Dropzone.js',我是否需要在客户端的每个 html View 上加载它?

最佳答案

您可以在 angular-cli.json 配置文件中添加文件。

示例:

 "scripts": [
"../node_modules/jquery/dist/jquery.js",
"../node_modules/tether/dist/js/tether.js",
"../node_modules/bootstrap/dist/js/bootstrap.js",
"../node_modules/highcharts/highcharts.js",
"../node_modules/chart.js/dist/Chart.js",
"../node_modules/chart.js/dist/Chart.min.js"

]

直接添加所有JS构建将生成脚本捆绑版本,不需要任何导入

关于javascript - 在 Angular2 中添加外部库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40841221/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com