我在使用ElementRef时遇到以下错误:
通用类型'ElementRef'需要2个类型参数
我发现的唯一建议是更新我的角度版本(使用最新版本)。我更新了每个软件包。可悲的是什么都没有改变。代码:
组件
import { Component, OnInit,AfterViewInit,OnDestroy,ViewChild,ChangeDetectorRef,ElementRef} from '@angular/core';
export class UserComponent implements OnInit, AfterViewInit, OnDestroy {
@ViewChild('cardInfo') cardInfo: ElementRef;
}
ElementRef引发错误
package.json:
{
"name": "demo-web",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^6.1.4",
"@angular/common": "^6.1.4",
"@angular/compiler": "^6.1.4",
"@angular/core": "^6.1.4",
"@angular/forms": "^6.1.4",
"@angular/http": "^6.1.4",
"@angular/platform-browser": "^6.1.4",
"@angular/platform-browser-dynamic": "^6.1.4",
"@angular/router": "^6.1.4",
"angular-jsvat": "^1.1.0",
"core-js": "^2.5.4",
"ng2-validation": "^4.2.0",
"rxjs": "^6.0.0",
"zone.js": "~0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "^0.7.5",
"@angular/cli": "~6.1.5",
"@angular/compiler-cli": "^6.1.4",
"@angular/language-service": "^6.1.4",
"@types/jasmine": "~2.8.6",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.2.1",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~1.7.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.0",
"karma-jasmine": "~1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "^5.4.0",
"ts-node": "~5.0.1",
"tslint": "~5.9.1",
"typescript": "~2.7.2"
}
}
答案 0 :(得分:0)
好吧,我为此花了几个小时,但终于找到了解决方案。它与打字稿有关。我将打字稿从2.7.2更新为2.9.2(全局和本地),并且错误不再显示。我认为在有关此问题的较早问题中发布的解决方案确实具有误导性。