簡體   English   中英

嘗試在 Angular 中使用 ViewChild 注釋時出錯

[英]Error when trying to use ViewChild annotation in Angular

我正在嘗試像這樣使用 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/

在我的例子中,VSCode 以某種方式創建了一個 ViewChild function(自動?當我復制粘貼 @ViewChild 注釋時?)。 因此,請檢查您的代碼,如果您的 ts 文件中存在 ViewChild function 並將其刪除。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM