ViewChild 更改检测抛出 ExpressionChangedAfterItHasBeenCheckedError

问题描述 投票:0回答:1
angular typescript angular-components angular2-changedetection
1个回答
0
投票

您可以只使用

static
ViewChild
属性,这将在设置为 true 时在更改检测运行之前评估视图子级,并可能消除错误!

静态

true 表示在更改检测运行之前解析查询结果, false 表示在更改检测之后解析。默认为 false。

@ViewChild('formTemplate', { static: true }) formTemplate: TemplateRef<any>;
@ViewChild('formComponent', { static: true }) formComponent: FormComponent;
© www.soinside.com 2019 - 2024. All rights reserved.