首页 > 解决方案 > 错误 TS2554:预期 2 个参数,但使用 @ViewChild 得到 1 个

问题描述

我使用 ViewChild 如下:

@ViewChild("InternalMedia") localStream;
@ViewChild("emoji") mEmoji;

在 angular-7.x 之前工作正常

一旦我将它升级到 angular-8.x,它就开始出现以下错误

.../call_emoji/component.ts(41,4): error TS2554: Expected 2 arguments, but got 1.

我检查了https://angular.io/api/core/ViewChild,当我将其更改为

@ViewChild("InternalMedia",{static:false}) remoteStream;

有用。我没有得到静态的作用以及像以前一样工作的价值是什么?

标签: angulartypescriptangular7viewchildangular8

解决方案


迁移到 Angular 8 后,您应该手动声明它是否是静态的

@ViewChild(QuilldEditorComponent, {static: true}) quillEditorComponentInstance;

如果您还有其他问题可以询问他们或了解更多详细信息,请阅读此问题 https://github.com/angular/angular-cli/issues/14553 或查看官方文档 https://angular.io/guide/static -查询迁移

// query results available in ngOnInit
@ViewChild('foo', {static: true}) foo: ElementRef; 

OR

// query results available in ngAfterViewInit
@ViewChild('foo', {static: false}) foo: ElementRef;


推荐阅读