Tuesday, January 21, 2020

Angular 8 demands that you detail when a ViewChild will initialize.

What was...

@ViewChild(MatPaginator) paginator: MatPaginator;

 
 

...in Angular 6 has become...

@ViewChild(MatPaginator, {static: true}) paginator: MatPaginator;

 
 

...in Angular 8. The true will initialize the ViewChild upon ngOnInit while false waits until ngAfterViewInit, and for a ContentChild instead of a ViewChild the true behaves the same while the false uses ngAfterContentInit. You will use ContentChild to grab at what is in ng-content in lieu of just elements in your template. A sandboxed Shadow DOM is handed in to a component as a template typically, but if you are injecting your own guts into a third party component the insertion is a Light DOM and the third party template may use a ContentChild to grab at what it expects in your handed-in gunk. See this and this.

No comments:

Post a Comment