error TS2554: Expected 2 arguments, but got 1 with @ViewChild

Akhilesh Kumar picture Akhilesh Kumar · Jun 6, 2019 · Viewed 40k times · Source

I was using ViewChild as follows:

@ViewChild("InternalMedia") localStream;
@ViewChild("emoji") mEmoji;

Which was working fine till angular-7.x

as soon as I upgraded it to angular-8.x it started giving following error

.../call_emoji/component.ts(41,4): error TS2554: Expected 2 arguments, but got 1.

I checked https://angular.io/api/core/ViewChild and when I change it to

@ViewChild("InternalMedia",{static:false}) remoteStream;

It works. I'm not getting what static does and what should be it's value to work as previous?

Answer

Stefan Morcodeanu picture Stefan Morcodeanu · Jun 25, 2019

After migration to Angular 8 you should declare manually if it's static or not

@ViewChild(QuilldEditorComponent, {static: true}) quillEditorComponentInstance;

If you have further questions ask them or for more details please read this issue https://github.com/angular/angular-cli/issues/14553 or take a look at offical documentation https://angular.io/guide/static-query-migration

// query results available in ngOnInit
@ViewChild('foo', {static: true}) foo: ElementRef; 

OR

// query results available in ngAfterViewInit
@ViewChild('foo', {static: false}) foo: ElementRef;