简体   繁体   English

在Angular 5项目中包含jquery-ui

[英]Include jquery-ui in Angular 5 project

I am trying to add jquery-ui to my project in Angular 5 since I had to create a feature using jquery-ui, but i cannot get it to work. 我试图将jQuery-ui添加到我在Angular 5中的项目中,因为我不得不使用jquery-ui创建一个功能,但是我无法使其正常工作。 I get the error: 我得到错误:

TypeError: WEBPACK_IMPORTED_MODULE_10_jquery (...).droppable is not a function TypeError: WEBPACK_IMPORTED_MODULE_10_jquery (...)。droppable不是函数

I tried putting the jquery-ui script to my assets folder and load it in index.html, but that doesn't work since it loads before jquery. 我尝试将jquery-ui脚本放到我的资产文件夹中并将其加载到index.html中,但这不起作用,因为它在jquery之前加载。 Now i used this code to add it in component where I use it, and it adds it after jquery but still get the error above: 现在,我使用此代码将其添加到使用它的组件中,并将其添加到jquery之后,但仍然出现上述错误:

if (!document.querySelector('script[src="./assets/js/jquery-ui.min.js"]')) {
      const s = document.createElement('script');
      s.type = 'text/javascript';
      s.src = './assets/js/jquery-ui.min.js';
      document.head.appendChild(s);
    }

When i run npm install jquery-ui and add scripts to angular-cli.json, same error occurs... Dont know what else to try... 当我运行npm install jquery-ui并将脚本添加到angular-cli.json时,发生相同的错误...不知道还有什么尝试...

EDIT: This answer finally worked for me: Angular4 can't find Jquery-UI functions 编辑:这个答案终于对我有用Angular4找不到Jquery-UI函数

You can install jquery-ui-dist to avoid adding the file in your index file: 您可以安装jquery-ui-dist以避免将文件添加到索引文件中:

npm install jquery
npm install jquery-ui-dist

Add this in script inside angular-cli.json 将其添加到angular-cli.json中的script

 "../node_modules/jquery/dist/jquery.min.js",
 "../node_modules/jquery-ui-dist/jquery-ui.js"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM