您好,欢迎来到世旅网。
搜索
您的当前位置:首页Angular 8.x使用ViewChild报错

Angular 8.x使用ViewChild报错

来源:世旅网

错误:

error TS25: Expected 2 arguments, but got 1.

应有 2 个参数,但获得 1 个。ts(25)

core.d.ts(7888, 47): An argument for 'opts' was not provided.

原因:ViewChild需要两个参数,并没有提供opts

官网解释:

static - whether or not to resolve query results before change detection runs (i.e. return static results only). If this option is not provided, the compiler will fall back to its default behavior, which is to use query results to determine the timing of query resolution. If any query results are inside a nested view (e.g. *ngIf), the query will be resolved after change detection runs. Otherwise, it will be resolved before change detection runs.

此段解释在中文文档中并没有被翻译,大体意思如下:

static - 是否在更改检测运行之前解析查询结果(即只返回静态结果)。如果不提供此选项,编译器将退回到其默认行为,即使用查询结果来确定查询解析的时间。如果任何查询结果位于嵌套视图中(例如*ngIf),则在运行更改检测后将解析该查询。否则,它将在变更检测运行之前被解析。

解决:(按他说的添加参数就行了)


  @ViewChild('child',{static:true}) child:any;

//或者

  @ViewChild('child',{static:false}) child:any;  

 

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- esig.cn 版权所有 湘ICP备2023023988号-3

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务