Error when trying to use ViewChild annotation in Angular

325 views Asked by At

I am trying to use ViewChild like this:

@ViewChild('hello', { static: false }) 
divHello?: ElementRef;

This is the template:

<div class="wrap" #hello>
Some test data
</div>

But, the ViewChild annotation is showing this error:

Unable to resolve signature of property decorator when called as an expression.
  This expression is not callable.
    Type 'void' has no call signatures.

Making the target ES5 is not my solution, since I don't want that in my case.

Is there any way to use ViewChild? I was referring to this tutorial: https://www.tektutorialshub.com/angular/renderer2-angular/

1

There are 1 answers

1
PeterB On

In my case VSCode created a ViewChild function somehow (automatically? when I copy-pasted the @ViewChild annotation?). So check your code if there is a ViewChild function in you ts file and delete it.