javascript Angular 5 ng-bootstrap Type 'ElementRef' 不是通用的错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50780419/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 09:16:18  来源:igfitidea点击:

Angular 5 ng-bootstrap Type 'ElementRef' is not generic err

javascriptnode.jsangularangular5ng-bootstrap

提问by GustavoFraga

I use angular 5 and ng-bootstrap in these versions:

我在这些版本中使用 angular 5 和 ng-bootstrap:

  "private": true,
  "dependencies": {
    "@angular/animations": "^5.2.0",
    "@angular/common": "^5.2.0",
    "@angular/compiler": "^5.2.0",
    "@angular/core": "^5.2.0",
    "@angular/forms": "^5.2.0",
    "@angular/http": "^5.2.0",
    "@angular/platform-browser": "^5.2.0",
    "@angular/platform-browser-dynamic": "^5.2.0",
    "@angular/router": "^5.2.0",
    "@ng-bootstrap/ng-bootstrap": "^2.1.0",
    "angular-in-memory-web-api": "^0.5.4",
    "angular2-moment": "^1.9.0",
    "bootstrap": "^4.1.1",
    "core-js": "^2.4.1",
    "date-util": "^1.2.1",
    "material-icons": "^0.2.1",
    "ngx-bootstrap": "^3.0.0",
    "normalize.css": "^8.0.0",
    "rxjs": "^5.5.6",
    "zone.js": "^0.8.19"
  },

when I get ng serve has this error:

当我收到 ng serve 时出现此错误:

**

Failed to compile.

node_modules/@ng-bootstrap/ng-bootstrap/buttons/radio.d.ts(58,96): error TS2315: Type 'ElementRef' is not generic. node_modules/@ng-bootstrap/ng-bootstrap/datepicker/datepicker-input.d.ts(121,67): error TS2315: Type 'ElementRef' is not generic. node_modules/@ng-bootstrap/ng-bootstrap/datepicker/datepicker.d.ts(115,208): error TS2315: Type 'ElementRef' is not generic. node_modules/@ng-bootstrap/ng-bootstrap/dropdown/dropdown.d.ts(12,45): error TS2315: Type 'ElementRef' is not generic. node_modules/@ng-bootstrap/ng-bootstrap/dropdown/dropdown.d.ts(29,45): error TS2315: Type 'ElementRef' is not generic. node_modules/@ng-bootstrap/ng-bootstrap/dropdown/dropdown.d.ts(37,44): error TS2315: Type 'ElementRef' is not generic. node_modules/@ng-bootstrap/ng-bootstrap/modal/modal-window.d.ts(13,40): error TS2315: Type 'ElementRef' is not generic.

**

编译失败。

node_modules/@ng-bootstrap/ng-bootstrap/buttons/radio.d.ts(58,96): 错误 TS2315: 类型 'ElementRef' 不是通用的。node_modules/@ng-bootstrap/ng-bootstrap/datepicker/datepicker-input.d.ts(121,67): 错误 TS2315: 类型 'ElementRef' 不是通用的。node_modules/@ng-bootstrap/ng-bootstrap/datepicker/datepicker.d.ts(115,208): 错误 TS2315: 类型 'ElementRef' 不是通用的。node_modules/@ng-bootstrap/ng-bootstrap/dropdown/dropdown.d.ts(12,45): 错误 TS2315: 类型 'ElementRef' 不是通用的。node_modules/@ng-bootstrap/ng-bootstrap/dropdown/dropdown.d.ts(29,45): 错误 TS2315: 类型 'ElementRef' 不是通用的。node_modules/@ng-bootstrap/ng-bootstrap/dropdown/dropdown.d.ts(37,44): 错误 TS2315: 类型 'ElementRef' 不是通用的。node_modules/@ng-bootstrap/ng-bootstrap/modal/modal-window.d。

回答by Azac

I had the same issue. So I unistalled the ng-bootstrap.

我遇到过同样的问题。所以我卸载了ng-bootstrap.

Then I reinstall it directly whit 2.0.0version.

然后我直接重新安装它的白色2.0.0版本。

npm install --save @ng-bootstrap/[email protected]

npm install --save @ng-bootstrap/[email protected]

回答by pkozlowski.opensource

You need to use Angular 6.0.0 or later with ng-bootstrap >= 2.0.0. npm / yarn install should have given you warning during installation.

您需要在 ng-bootstrap >= 2.0.0 的情况下使用 Angular 6.0.0 或更高版本。npm / yarn install 应该在安装过程中给你警告。

Reverting to ng-bootstrap 2.0.0 is nota solution as you will simply be stuck with this version of a library and won't receive updates / fixes.

恢复到 ng-bootstrap 2.0.0不是一个解决方案,因为您将被困在这个版本的库中,并且不会收到更新/修复。

To properly resolve this issue you need to either:

要正确解决此问题,您需要:

  • upgrade Angular to version 6.0.0 or later (recommended)
  • use lates ng-bootstrap still compatible with Angular 5.x (1.1.2)
  • 将 Angular 升级到 6.0.0 或更高版本(推荐)
  • 使用仍然与 Angular 5.x (1.1.2) 兼容的 lates ng-bootstrap

回答by Shalika Akalanka

Change your ng-bootstrap version to "2.0.0"

将您的 ng-bootstrap 版本更改为“2.0.0”

"@ng-bootstrap/ng-bootstrap": "2.0.0"

"@ng-bootstrap/ng-bootstrap": "2.0.0"

and then npm install& try serve the application.

然后npm install尝试为应用程序提供服务。

I faced the same issue and above method worked for me.

我遇到了同样的问题,上述方法对我有用。

回答by EnjiLenin

I am suddenly facing the same issue.

我突然面临同样的问题。

In my case I was using ng-boostrasp 2.0.0, but I was specifying dependencies this way:

就我而言,我使用的是 ng-boostasp 2.0.0,但我以这种方式指定了依赖项:

"@ng-bootstrap/ng-bootstrap": "^2.0.0"

Which at some point in time (based on logs from past successful builds : somewhere since june the 1st) started to pickup version 2.1.0.

在某个时间点(基于过去成功构建的日志:自 6 月 1 日以来的某个地方)开始获取 2.1.0 版。

So I changed my package.json to pick exactly 2.0.0:

所以我改变了我的 package.json 来选择 2.0.0:

"@ng-bootstrap/ng-bootstrap": "2.0.0"

This fixed the problem from me.

这解决了我的问题。

回答by Athi

After installing the latest ng- bootstrap which showed an error on serve.

安装最新的 ng-bootstrap 后,在服务上显示错误。

Finally, doing this

最后,这样做

npm install --save @ng-bootstrap/[email protected]

helped.

有帮助。

回答by Arpan Das

Install ng-bootstrap checking the version compatibility.

安装 ng-bootstrap 检查版本兼容性。

ng-bootstrap    Angular  Bootstrap CSS
1.x.x             5.0.2   4.0.0
2.x.x             6.0.0   4.0.0
3.x.x             6.1.0   4.0.0
4.x.x             7.0.0   4.0.0
5.x.x             8.0.0   4.3.1 

You can find the version details under versions tab here, https://www.npmjs.com/package/@ng-bootstrap/ng-bootstrap

您可以在此处的版本选项卡下找到版本详细信息, https://www.npmjs.com/package/@ng-bootstrap/ng-bootstrap