Anglular8的@ViewChild的变化

配置ViewChild / ContentChild查询的时间
使用此功能时,必须提供静态标志以定义什么时候须要解析ViewChild和ContentChild实例。
使用此功能时,必须提供静态标志以定义什么时候须要解析ViewChild和ContentChild实例。code

// Ensure Change Detection runs before accessing the instance
@ContentChild('foo', { static: false }) foo!: ElementRef;
// If you need to access it in ngOnInt hook
@ViewChild(TemplateRef, { static: true }) foo!: TemplateRef;

以上功能不适用于ViewChildren或ContentChildren。它们将在变动检测运行后解析。
须要注意的是,设置static: true将不容许您从动态模板分辨率(例如*ngIf)得到结果。
添加了原理图支持以将现有代码迁移到此语法,由于将使用此语法Ivy 。您能够运行ng update @angular/core以迁移现有代码。it

相关文章
相关标签/搜索