类型“ AbstractControl”上不存在属性“控件”。对于数组元素?

时间:2019-09-04 21:37:44

标签: angular angular7 angular8

组件代码为:

this.orderForm = this.formBuilder.group({
      items: this.formBuilder.array([])
});

表格为:

<form [formGroup]="orderForm">
<div
      class="form-group"
      formArrayName="items"
      *ngFor="let item of orderForm.get('items').controls; let i = index"
    >
</div>
</form>

我收到错误消息:

  

类型“ AbstractControl”上不存在属性“控件”。

我该如何解决:

1 个答案:

答案 0 :(得分:2)

尝试这样

get items() : FormArry {
 return this.orderForm.get('items') as FormArray
}

模板

<form [formGroup]="orderForm">
  <div formArrayName="items">
    <div class="form-group" *ngFor="let item of items.controls; let i = index">
     ...
    </div>
  </div>
</form>