How to initialize ElementRef Angular - Typescript

Viewed 4873

when I use

@ViewChild('serachField', { static: false }) serachField: ElementRef<HTMLInputElement>

I get the error

Property 'serachField' has no initializer and is not definitely assigned in the constructor.

I usually initialise the variable, But I'm unsure how to do it in this case

I've tried

@ViewChild('serachField', { static: false }) serachField: ElementRef<HTMLInputElement> = new ElementRef<HTMLInputElement>(--unsure what the parameter should be--)

I get:

Expected 1 arguments, but got 0.ts(2554)
core.d.ts(2253, 17): An argument for 'nativeElement' was not provided.
1 Answers

Thank you @Isbn

I used:

@ViewChild('serachField', { static: false }) serachField: ElementRef<HTMLInputElement> = {} as ElementRef;
Related