【问题标题】:How to use jQuery Plugin with Angular 5 and TypeScript 2.8.1?如何在 Angular 5 和 TypeScript 2.8.1 中使用 jQuery 插件?
【发布时间】:2018-10-04 01:06:38
【问题描述】:

我想使用 TypeScript 2.8.1 在 Angular 5 项目中导入 jQuery。 我关注Ervin Llojku solution,但这不是诀窍:

使用 npm 安装 jquery

npm install --save jquery

使用 npm 安装 jquery

npm install --save-dev @types/jquery

将脚本添加到 .angular-cli.json

"apps": [{
  ...
  "scripts": [
    "../node_modules/jquery/dist/jquery.min.js",
  ],
  ...
}]

我也尝试在 app.module.ts 或组件中添加这些导入:

import * as $ 'jquery';

无论我尝试什么 TypeScript 编译器都会抛出这个错误:

Error:(7, 15) TS2497: Module ''jquery'' resolves to a non-module entity and cannot be imported using this construct.

【问题讨论】:

    标签: jquery angular typescript angular5 typescript2.8


    【解决方案1】:

    我已经关注another answer 并替换了

    import * as $ 'jquery';
    

    import 'jquery';
    

    app.module.ts 中,一切似乎都正常。

    我仍然不知道这个错误是由 Angular 5 还是 TypeScript 2.8.1 引起的...

    或者可能是 Angular 生成的 tsconfig.json

    "compilerOptions": {
      "moduleResolution": "node",
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-16
      • 2012-09-25
      • 1970-01-01
      • 2019-12-16
      • 2017-10-11
      • 1970-01-01
      • 2018-01-30
      • 2017-04-02
      相关资源
      最近更新 更多