angular.2在index.html中引用外部js文件 [英] angular 2 referencing external js file in index.html

查看:192
本文介绍了angular.2在index.html中引用外部js文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用angular cli工具进行简单的angular 2应用程序.在我的代码中,我必须在index.html中包含jquery.js文件.jquery.js位于node_modules目录下,但该语句

I am making a simple angular 2 application using angular cli tool. In my code I have to include jquery.js file in my index.html. jquery.js is under node_modules directory but the statement

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

似乎不起作用:

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

Failed to load resource: http://localhost:4200/node_modules/jquery/dist/jquery.js the server responded with a status of 404 (Not Found)

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

How can I make sure that the jquery.js is included in index.html? Thanks for any help.

推荐答案

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

In order to include a global library, you have to add the jquery.js file in the scripts array from angular-cli.json:

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

此后,如果已启动 ng serve ,请重新启动.

After this, restart ng serve if it is already started.

这篇关于angular.2在index.html中引用外部js文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆