Angular如何解决@ViewChild中的错误需要2个参数,但得到1.ts(2554)?

时间:2019-08-23 10:12:04

标签: angular viewchild

@@@@@@@@@@@@@@@@@@@@@@@@@·····························································································································································································································

我是一名新手,现在我被困在一个我不明白为什么我在导出类@ViewChild('namInput')上遇到此错误的地方,然后用红色加下划线我似乎无法解决此问题。我也做了更新,但还是一样。有人可以帮我吗?

代码示例:

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

导出类ShoppingEditComponent实现OnInit {

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

1 个答案:

答案 0 :(得分:0)

@ViewChild装饰器已将Angular 8版本中的options参数设为必需。

这里是一个例子:

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

或者当然,您可以根据需要将其设置为True。