您可以只使用
static
的
ViewChild
属性,这将在设置为 true 时在更改检测运行之前评估视图子级,并可能消除错误!
true 表示在更改检测运行之前解析查询结果, false 表示在更改检测之后解析。默认为 false。
@ViewChild('formTemplate', { static: true }) formTemplate: TemplateRef<any>;
@ViewChild('formComponent', { static: true }) formComponent: FormComponent;