angular - 错误 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;
有用。我没有得到静态的作用以及像以前一样工作的价值是什么?
解决方案
迁移到 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;
推荐阅读
- blockchain - 我的智能合约没有响应并且错误提示 web3 未定义
- youtube - YouTube 嵌入在特定时间开始不起作用
- apache-spark - 从 spark 编写 AVRO 时 Iceberg 不工作
- android - 创建一个 MPAndroidChart 来显示数据,但是没有显示任何内容
- java - org.apache.catalina.connector.ClientAbortException:java.io.EOFException:在套接字上读取了意外的 EOF
- node.js - mongoose.connect 函数给出错误信息
- java - 如何将捕获的图像保存到图库?
- docker-swarm - Docker Windows 主节点“docker swarm init”导致同一虚拟网络中的工作节点不再看到主节点
- loops - 我正在与一个班级一起改变声音的音高,但我无法让声音循环播放
- mysql - 在mysql查询中,当转换十进制值时,它显示不同的值