4

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!

Jayesh Vyas
  • 1,145
  • 3
  • 15
  • 35
  • Remove `, null` from `@ViewChild('subjectbox', null)` and initialize the ref to an empty object. `@ViewChild('subjectbox') private elementRefsub: ElementRef = {} as ElementRef;` – Sixteen Dec 20 '21 at 08:12

1 Answers1

4

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;
huan feng
  • 7,307
  • 2
  • 32
  • 56