0

Components code is:

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

Form is:

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

I get error message:

Property 'controls' does not exist on type 'AbstractControl'.

How can I fix it:

POV
  • 11,293
  • 34
  • 107
  • 201

1 Answers1

1

try like this

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

template

<form [formGroup]="orderForm">
  <div formArrayName="items">
    <div class="form-group" *ngFor="let item of items.controls; let i = index">
     ...
    </div>
  </div>
</form>
Muhammed Albarmavi
  • 23,240
  • 8
  • 66
  • 91