When trying ViewChild I am getting the error. Error is \"An argument for \'opts\' was not provided.\"
Both @ViewChild is giving the error.
In Angular 8, ViewChild has another param
@ViewChild('nameInput', {static: false}) component
I resolved my issue like below
@ViewChild(MatSort, {static: false}) sort: MatSort;
Try this in angular 8.0:
@ViewChild('result',{static: false}) resultElement: ElementRef;
In Angular 8, ViewChild always takes 2 param, and second params always has static: true or static: false
You can try like this:
@ViewChild('nameInput', {static: false}) component
Also,the static: false
is going to be the default fallback behaviour in Angular 9.
What are static false/true: So as a rule of thumb 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. This is
also what you want to go for when you have a structural directive
(i.e. *ngIf) on your element in your template.
That also resolved my issue.
@ViewChild('map', {static: false}) googleMap;
Use this
@ViewChild(ChildDirective, {static: false}) Component