gpt4 book ai didi

angular 2 在 index.html 中引用外部 js 文件

转载 作者:太空狗 更新时间:2023-10-29 17:23:16 25 4
gpt4 key购买 nike

我正在使用 angular cli 工具制作一个简单的 angular 2 应用程序。在我的代码中,我必须在 index.html 中包含 jquery.js 文件。 jquery.js 在 node_modules 目录下但是声明

<script src="../node_modules/jquery/dist/jquery.js"></script>

在 index.html 中似乎不起作用:

无法加载资源:http://localhost:4200/node_modules/jquery/dist/jquery.js服务器响应状态为 404(未找到)

如何确保 jquery.js 包含在 index.html 中?感谢您的帮助。

最佳答案

为了包含全局库,您必须在 angular-cli.json 的 scripts 数组中添加 jquery.js 文件:

"scripts": [
"../node_modules/jquery/dist/jquery.js"
]

在此之后,如果 ng serve 已经启动,请重新启动它。

关于angular 2 在 index.html 中引用外部 js 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41376263/

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