【问题标题】:Error when trying to use ViewChild annotation in Angular尝试在 Angular 中使用 ViewChild 注释时出错
【发布时间】:2021-05-01 17:00:38
【问题描述】:

我正在尝试像这样使用 ViewChild:

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

这是模板:

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

但是,ViewChild 注释显示此错误:

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

制作目标 ES5 不是我的解决方案,因为我不希望这样。

有什么方法可以使用 ViewChild 吗?我指的是这个教程:https://www.tektutorialshub.com/angular/renderer2-angular/

【问题讨论】:

标签: angular viewchild angular-renderer2 elementref


【解决方案1】:

在我的情况下,VSCode 以某种方式创建了 ViewChild 函数(自动?当我复制粘贴 @ViewChild 注释时?)。因此,请检查您的代码,如果您的 ts 文件中有 ViewChild 函数并将其删除。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-25
    • 2017-08-19
    • 2021-08-11
    • 2016-04-29
    • 2020-07-23
    • 2015-08-16
    相关资源
    最近更新 更多