Angular @ViewChild() error: Expected 2 arguments, but got 1
In Angular 8 , ViewChild takes 2 parameters @ViewChild(ChildDirective, {static: false}) Component
In Angular 8 , ViewChild takes 2 parameters @ViewChild(ChildDirective, {static: false}) Component
In most cases you will want to use {static: false}. Setting it like this will ensure query matches that are dependent on binding resolution (like structural directives *ngIf, etc…) will be found. Example of when to use static: false: @Component({ template: ` <div *ngIf=”showMe” #viewMe>Am I here?</div> <button (click)=”showMe = !showMe”></button> ` }) export class … Read more
Use a setter for the ViewChild: private contentPlaceholder: ElementRef; @ViewChild(‘contentPlaceholder’) set content(content: ElementRef) { if(content) { // initially setter gets called with undefined this.contentPlaceholder = content; } } The setter is called with an element reference once *ngIf becomes true. Note, for Angular 8 you have to make sure to set { static: false }, … Read more