Angular4找不到Jquery-UI函数 [英] Angular4 can't find Jquery-UI functions

查看:80
本文介绍了Angular4找不到Jquery-UI函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了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 有什么想法我要去哪里吗?

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屋!

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