Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR in @ViewChild options must be an object literal in angular 9

I have upgraded my Angular project from Angular version 8 to Angular version 9. it was upgraded successfully but when I am running the project on localhost or when I am trying to build my project it is giving me the following error.

ERROR in @ViewChild options must be an object literal

here is my @ViewChild syntax in some files that I am using.

  @ViewChild('subjectbox',null) private elementRefsub: ElementRef;

I don't know what I am doing wrong here.

can anyone please help with this?

Thanks in Advance!

like image 444
Jayesh Vyas Avatar asked Nov 01 '25 22:11

Jayesh Vyas


1 Answers

If you do not need a metadata, you can write:

@ViewChild('subjectbox') private elementRefsub: ElementRef;

Metadata Properties: (examples for properties listed for your reference)

selector - The directive type or the name used for querying.

read - Used to read a different token from the queried elements.

@ViewChild('subjectbox', { read: ElementRef }) private elementRefsub: ElementRef;

static - True to resolve query results before change detection runs, false to resolve after change detection. Defaults to false.

@ViewChild('subjectbox', { static: false }) private elementRefsub: ElementRef;
like image 141
huan feng Avatar answered Nov 03 '25 12:11

huan feng



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!