类型 'ElementRef' 不是通用的 [英] Type 'ElementRef' is not generic

查看:25
本文介绍了类型 'ElementRef' 不是通用的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个在 Angular 5 中使用 Material Component 的项目.我确实更新了我的 Visual 代码,但我不知道发生了什么.我面临一个问题类型 'ElementRef' 不是通用的."我从早上就一直在纠结这个问题.

I am working with a project using Material Component in Angular 5. I did update my Visual code but I don't know what happened. I am facing an issue "Type 'ElementRef' is not generic." I have been stuck on this issue since morning.

此行错误

_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 版本.

I think the problem could be if your you are using Angular Material 6 but still Angular 5 then you will get this error. When installing Angular Material 6 RC 12 it's looking for a peer dependency for Angular 6 Beta 0 while I had a Angular 5.x.x version.

解决方案:

  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 的所有版本号都将保持同步,因此了解什么和兼容性会更容易,希望你会'不会再有这个问题了.

PS: They announced at ng-conf 2018 that from version 6 onwards all the version numbers for Angular, Angular Material and Angular CLI will stay in sync so knowing what goes with what and compatibility will be much easier and hopefully you won't have this problem again.

这篇关于类型 'ElementRef' 不是通用的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆