Angular (4.1.3) ng-select2 错误

Aks*_*ayP 2 javascript node.js npm angular

我安装了ng-select2 包。而且我收到此错误,并且代码在“ng serve”之后无法编译。

  • 节点版本为 8.10.0
  • npm 版本 6.0.0
  • 项目清单

操作系统 Windows 7

ERROR in d:/PATH-TO-PROJECT-FOLDER/node_modules/@types/select2/index.d.ts (233,49): 'JQuery' only refers to a type, but is being used as a namespace here.

ERROR in D:/PATH-TO-PROJECT-FOLDER/node_modules/ng-select2/ng-select2/ng-select2.component.ts (188,18): Cannot find name 'Select2Options'.

ERROR in /src/app/pages/dashboard/dashboard.component.ts (91,19): Cannot find name 'Select2Options'.

// Dashboard component ts(91, 19) error + I've also added import to it:
public options: Select2Options;
Run Code Online (Sandbox Code Playgroud)

我试过的解决方案是:

  • 根据文档,添加导入并在@NgModule 中导入到 app.module.ts
  • 我也安装了 jquery@3.2.1 和 @types/jquery@2.0.41。
  • npm 缓存验证,然后 npm cache clean --force 和更新的 npm
  • 删除 package-lock.json 然后运行 ​​npm install 但这似乎不起作用。

tja*_*dli 5

如 github 问题所述:在最新版本 4.0.45 中,接口 Select2Options 已删除/重命名为 Options

为了解决这个问题,我只需通过运行 npm install @ types/select2@4.0.44 --save 将包降级到 4.0.44,这对我有用。

https://github.com/NejcZdovc/ng2-select2/issues/124