簡體   English   中英

如何在Angular 5和TypeScript 2.8.1中使用jQuery插件?

[英]How to use jQuery Plugin with Angular 5 and TypeScript 2.8.1?

我想使用TypeScript 2.8.1在Angular 5項目中導入jQuery。 我遵循Ervin Llojku解決方案,但這不是竅門:

使用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或component中:

import * as $ 'jquery';

我嘗試使用TypeScript編譯器拋出此錯誤:

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

我遵循了另一個答案 ,我替換了

import * as $ 'jquery';

import 'jquery';

app.module.ts中 ,一切似乎都還可以。

仍然我不知道此錯誤是否是由於Angular 5或TypeScript 2.8.1引起的...

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM