Angular4 找不到 Jquery-UI 函数 [英] Angular4 can't find Jquery-UI functions
问题描述
我已经安装了 Jquery 和 Jquery-ui
I have installed Jquery and Jquery-ui
npm install --save jquery jquery-ui
文件位于 node_modules 目录中.我有一个声明 Jquery 的组件
The files are in the node_modules directory. I have a component that declares Jquery
declare var $: JQueryStatic;
我的 jquery 函数工作得很好,但 jquery-ui 函数不行.
My jquery functions work just fine, but the jquery-ui functions do not.
$('some-div').dropdown(); // works
$('window').draggable(); // draggable is not recognized as a function
所以,显然我对 jquery-ui 的包含是不正确的.我尝试在我的 .angular-cli.json 页面中包含一堆不同的东西,但没有成功.
So, obviously my inclusion for jquery-ui is not correct. I tried including a bunch of different things in my .angular-cli.json page to no success.
我在 .angular-cli 文件中尝试过的事情:
Things I have tried in my .angular-cli file:
...
"scripts": [
"../node_modules/jquery/dist/jquery.min.js",
"../node_modules/jquery-ui/ui/widgets/draggable.js",
"../node_modules/jquery-ui/ui/draggable.js",
]
我尝试直接导入到组件中,但这在定义 $ui 时出现了问题.我也遇到了未定义的错误.
I tried importing directly into the component, but that gave problems with $ui being defined. I also got errors that defined is not defined.
我看过 npm jquery-ui 和 jquery-ui 升级指南
有什么想法我哪里出错了吗?
Any ideas where I am going wrong?
推荐答案
在 angular-cli.json 中定义 jquery-ui(避免在 index.html 中添加)的解决方案是:
The solution to define jquery-ui in angular-cli.json (and avoid to add it in index.html) is:
1 : 导入 jquery-ui-dist
1 : Import jquery-ui-dist
npm install jquery jquery-ui-dist
2: 在 angular-cli.json 中添加脚本
2: Add scripts in angular-cli.json
"scripts": [
"../node_modules/jquery/dist/jquery.min.js",
"../node_modules/jquery-ui-dist/jquery-ui.js"
],
来源:https://stackoverflow.com/a/38795318
这篇关于Angular4 找不到 Jquery-UI 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!