javascript - 在 Angular 5 项目中包含 jquery-ui

标签 javascript jquery angular jquery-ui

我正在尝试将 jquery-ui 添加到 Angular 5 中的项目中,因为我必须使用 jquery-ui 创建一个功能,但我无法让它工作。我收到错误:

TypeError: WEBPACK_IMPORTED_MODULE_10_jquery(...).droppable is not a function

我尝试将 jquery-ui 脚本放入我的 asset 文件夹中并将其加载到 index.html 中,但这不起作用,因为它在 jquery 之前加载。现在我使用这段代码将其添加到我使用它的组件中,它在 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);
    }

当我运行 npm install jquery-ui 并将脚本添加到 angular-cli.json 时,会发生同样的错误...不知道还能尝试什么...

编辑:这个答案终于对我有用:Angular4 can't find Jquery-UI functions

最佳答案

您可以安装jquery-ui-dist以避免在索引文件中添加该文件:

npm install jquery
npm install jquery-ui-dist

将其添加到angular-cli.json内的script

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

关于javascript - 在 Angular 5 项目中包含 jquery-ui,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49030280/

相关文章:

javascript - Mongoose 保存不起作用 "id is not defined"

javascript - Ext JS 选项卡面板不适合窗口大小

javascript - Vue2 : data updated but html not?

javascript - Angular - 使用哈希策略时如何获取 URL?

angular - 如何在 Jest 中模拟 router.navigate 方法

javascript - 如何添加到react-redux中的状态数组

javascript - 哪个谷歌地图 API 用于在区域选择上呈现此鼠标

javascript - 当我点击提交按钮时,我的电子邮件没有发送,为什么?

javascript - 单击其他时取消选中复选框

angular - 带有angular2的非SPA