I'm studing Angular. How is better to configure the new Angular 8 view child?
@ViewChild('example', {read: ElementRef, static: false})
public example: ElementRef;
or
@ViewChild('example', {read: ElementRef, static: true})
public example: ElementRef;
Which is better? When should I use static:true
vs static:false
?
You can go for the following:
{ static: true }
needs to be set when you want to access the ViewChild
in ngOnInit
.
{ static: false }
can only be accessed in ngAfterViewInit
.