joler-botol
joler-botol

Reputation: 452

Error when trying to use ViewChild annotation in Angular

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/

Upvotes: 0

Views: 449

Answers (1)

PeterB
PeterB

Reputation: 1091

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.

Upvotes: 2

Related Questions