【发布时间】:2018-11-19 16:26:19
【问题描述】:
我在将 jQuery 级联下拉组件嵌入到我的 Angular 6 项目时遇到问题。尝试运行ng serve时出现错误:
错误:ENOENT:没有这样的文件或目录,打开 C:\nodeprojects\node_modules\jquery\dist\jquery.min.js.
以下是我将 jQuery 添加到 Angular 6 的步骤:
- 然
npm install jquery
' 并验证 jquery.min.js 位于上面列出的路径中。
-
修改了
angular.json(Angular 6 不再有 'angular-cli.json' 文件)并在'scripts []' 部分添加了jquery.min.js文件的相对路径。 我使用
app.component作为目标组件。在app.component.ts中输入declare var $: any;,在export class AppComponent implements OnInit()里面输入jquery自定义组件函数。
我试图嵌入 Angular 的 jquery 组件位于https://jsfiddle.net/brohjoe/zgc0n1q5/1/
HTML 被输入到app.component.html。我删除了对脚本 src 的引用,因为如上所述,缩小的 jquery 库在 angular.json 中列出,而 custom.js 代码如上所述嵌入在 app.component.ts 中。
运行 localhost:4200 后,唯一会显示的 ui 元素是没有数据的下拉菜单。
【问题讨论】:
-
看看this
-
谢谢维卡斯。那个网站有帮助。我在 jQuery 库的路径中有两个前导点,但 node_modules 目录和 angular.json 文件位于同一级别,因此删除前导点解决了问题。编译没有错误!
标签: jquery angular angular-cli