首页 > 解决方案 > 在新的 Angular 中查看孩子

问题描述

我正在学习 Angular。如何更好地配置新的 Angular 8 视图子项?

@ViewChild('example', {read: ElementRef, static: false})
public example: ElementRef;

或者

@ViewChild('example', {read: ElementRef, static: true})
public example: ElementRef;

哪个更好?我什么时候应该使用static:truevs static:false

标签: angularviewchild

解决方案


你可以去以下:

  • { static: true }ViewChild当您要访问in时需要设置ngOnInit

  • { static: false }只能在ngAfterViewInit.


推荐阅读