类型 'ElementRef' 不是泛型

Type 'ElementRef' is not generic

我正在使用 Angular 中的 Material 组件处理一个项目 5. 我确实更新了我的可视化代码,但我不知道发生了什么。我遇到了一个问题 "Type 'ElementRef' is not generic." 从早上起我就一直被这个问题困扰。

Error in this line

_inputElement: ElementRef<HTMLInputElement>;
constructor(toggleGroup: MatButtonToggleGroup, _changeDetectorRef: ChangeDetectorRef, _elementRef: ElementRef<HTMLInputElement>, _focusMonitor: FocusMonitor);

我认为问题可能是如果您正在使用 Angular Material 6 但仍然使用 Angular 5 那么您将收到此错误。安装 Angular Material 6 RC 12 时,它正在寻找 Angular 6 Beta 0 的对等依赖项,而我有一个 Angular 5.x.x 版本。

解决方案:

  1. 将 Angular Material 降级到 Angular 的相同主要版本(例如 v5.x.x)
  2. 将Angular和Material升级到最新的RC版本,在边缘生活。 (例如 v6.x.x RCx)

PS:他们在 ng-conf 2018 上宣布,从版本 6 开始,Angular、Angular Material 和 Angular CLI 的所有版本号将保持同步所以知道什么是什么以及兼容性会容易得多,希望你不会再遇到这个问题。

我在 Angular 5 应用程序中遇到与上述 ng-bootstrap 相同的错误。

ERROR in node_modules/@ng-bootstrap/ng-bootstrap/buttons/radio.d.ts(58,96): error TS2315: Type 'ElementRef' is not generic.

我的 package.json 中有 2.1.0 版本 "@ng-bootstrap/ng-bootstrap": "^2.1.0"

看来2.1.0版本在以后的版本中支持,所以决定将我的包ng-bootstrap降级到"@ng-bootstrap/ng-bootstrap": "^1.1.0"

然后,当我 运行 ng s 时,一切都按预期进行。