【问题标题】:angular 5 migration jquery not working角度5迁移jquery不起作用
【发布时间】:2017-12-07 06:25:26
【问题描述】:

我的 ANGULAR 5 应用程序出现问题。

我使用了一些需要 JQUERY 的组件,它在迁移之前可以正常工作我没有做任何更改。

我添加了我的组件 声明 var jQuery: any;

包装内。 json

    "jquery": "^3.2.1",
    "jquery-slimscroll": "^1.3.8",
    "jquery-sparkline": "^2.4.0",
    "jstree": "^3.3.4",

开发

    "@types/jquery": "^3.2.16",

角度剪辑

      "scripts": [
      "../node_modules/jquery/dist/jquery.js",
      "../node_modules/metismenu/dist/metisMenu.js",
      "../node_modules/jquery-sparkline/jquery.sparkline.js",
      "../vendor/pace/pace.min.js",
      "../node_modules/jstree/dist/jstree.min.js",
      "../node_modules/simplebar/dist/simplebar.js"
  ],

有人有想法吗?

【问题讨论】:

  • 您最终找到解决方案了吗?我有同样的问题。编译我的 Angular 应用程序,我得到 Module not found: Error: Can't resolve 'jquery' in...
  • 如果您在第一次编译时出现错误,我发现 JQUERY 错误。 - 如果我开始编译时没有错误 jQuery 被包含并且正在工作 - 如果我的编译在第一次编译时出现错误,就像它不包含一样

标签: jquery angular migration angular-cli angular5


【解决方案1】:

我尝试了关注并且对我来说工作正常

  1. npm i --save jquery [安装jquery v1.12.4 并在package.json 中添加为依赖项]
  2. 转到.angular-cli.json 并在scripts[] 添加如下。我正在使用引导程序,所以也添加了

    scripts: ["../node_modules/jquery/dist/jquery.min.js", "../node_modules/bootstrap/dist/js/bootstrap.js"]

  3. 将以下内容添加到您希望编写 jquery 函数的模块中

    import * as $ from 'jquery';

希望这能解决您的问题。请确保您在提到的位置有相应的文件。

【讨论】:

    【解决方案2】:

    如果您在第一次编译时出现错误,我发现了 JQUERY 错误。 - 如果我开始我的编译没有错误 jQuery 被包含并工作 - 如果我的编译在第一次编译时出现错误,就像它不包括在内

    所以让你的第一个构建工作,然后就没有问题了

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-10
      • 2017-11-08
      • 2018-11-21
      • 1970-01-01
      • 2023-03-14
      • 2012-09-08
      相关资源
      最近更新 更多