背景
Angular 7 升级到 Angular 8+, ViewChild中static设置为true还是false?
定义和用法
https://angular.io/api/core/ViewChild
和 React 中 ref 对应
- Property decorator that configures a view query.
- 查找DOM中匹配selector的第一个元素或者指令。
static应该如何设置
https://angular.io/guide/static-query-migration
查看plugin中static用true和false的场景
- 如果是动态创建(ngIf..., parent 有ngIf 也算)应该设置为false,且应该在ngAfterViewInit中访问,onInit中访问不到
- 如果是静态创建(没有 *ngIf...)应该设置为true, 直接创建,哪里都能访问
背景
Angular 7 升级到 Angular 8+, ViewChild中static设置为true还是false?
定义和用法
static应该如何设置