【问题标题】:Angular How to fix error in @ViewChild Expected 2 arguments, but got 1.ts (2554)? [duplicate]Angular 如何修复 @ViewChild 预期 2 个参数中的错误,但得到 1.ts (2554)? [复制]
【发布时间】:2019-12-28 15:37:36
【问题描述】:

Angular @ViewChild 错误:预期有 2 个参数,但得到了 1.ts (2554)。

我是一个新的学习者,现在我被困在一个点,我不明白为什么我会在我的导出类@ViewChild('namInput') 中收到这个错误,然后这行代码用红色下划线,并且我似乎无法解决这个问题。我也做了更新,但还是一样。有人可以帮我吗?

代码示例:

从 '@angular/core' 导入 { Component, OnInit, ElementRef, ViewChild};

导出类 ShoppingEditComponent 实现 OnInit {

  • @ViewChild('nameInput') nameInputRef: ElementRef;
  • @ViewChild('amountInput') amountInputRef: ElementRef;

【问题讨论】:

    标签: angular viewchild


    【解决方案1】:

    @ViewChild 装饰器在 Angular 8 版本中设置了 options 参数。

    这是一个例子:

        @ViewChild('nameInput', { static: false }) nameInputRef: ElementRef;
    

    当然,如果需要,您可以将其设置为 True。

    【讨论】:

      猜你喜欢
      • 2022-08-24
      • 2019-11-04
      • 1970-01-01
      • 2021-06-18
      • 2019-10-21
      • 1970-01-01
      • 1970-01-01
      • 2020-04-22
      • 1970-01-01
      相关资源
      最近更新 更多