Angular 通用类型ElementRef<;T、 任何>;需要2个类型参数和6个类型参数

Angular 通用类型ElementRef<;T、 任何>;需要2个类型参数和6个类型参数,angular,elementref,Angular,Elementref,我正在使用ElementRef访问DOM元素,但我得到一个错误 泛型类型ElementRef需要2个类型参数6 这是密码 导入 import { Component, OnInit, Input, ElementRef, Renderer2, AfterViewInit, ViewChild, ChangeDetectorRef, OnDestroy } from '@angular/core'; 代码 @ViewChild("transDtls") transModal: ElementR

我正在使用ElementRef访问DOM元素,但我得到一个错误

泛型类型ElementRef需要2个类型参数6

这是密码

导入

import { Component, OnInit, Input, ElementRef, Renderer2, AfterViewInit, ViewChild, ChangeDetectorRef, OnDestroy  } from '@angular/core';
代码

@ViewChild("transDtls") transModal: ElementRef;
上面的代码是我在大多数网站上看到的语法,我尝试过用这种方式

@ViewChild("transDtls") transModal: ElementRef<HTMLElement, any>;
@ViewChild(“transDtls”)transModal:ElementRef;
我在另一个网站上看到,它解决了IDE中的错误,但我在ng serve时在控制台中遇到了错误

错误 src/app/view/menu/transactions/transactions.component.ts(39,41):错误 TS2707:泛型类型“ElementRef”需要介于0和1之间的类型 争论


由于这个原因,我无法使用ElementRef,请帮助我了解angular。

您有两个错误吗?检查从何处导入
ElementRef
,确保没有重复项并发布当前错误
ElementRef
在使用时不需要键入。我在上面给出了导入,没有重复项,根据场景有两个不同的错误,我已经在上面描述过。尝试清除缓存
npm cache clean--force
并再次运行应该不会有任何问题。请使用on来重现错误。I user@ViewChild(“transDtls”)transModal:ElementRef;或@ViewChild(“transDtls”)transModal:ElementRef;