1
votes

I want to create form with a form array. But I get the failure

Cannot find control with path: 'strains -> i'

But my strainsFormcontains strains.

MODULE (TS)

  strainForm = new FormGroup({
    name: new FormControl('', Validators.required),
    daysToHarvest: new FormControl('', Validators.required)
  })
  strainsForm = new FormGroup({
    strains: new FormArray([this.strainForm])
  })

VIEW (HTML)

<form [formGroup]="strainsForm" (ngSubmit)="onSubmit()">

<section class="strains container-fluid">
  <div class="row">
    <div class="col-lg-4">
      <h3>Strains</h3>
    </div>
  </div>
  <article class="row">
    <div class="col-xs-12 col-sm-12 light-green">
      <fieldset class="col-xs-12 col-sm-12 light-green" formArrayName="strains">
        <!--<article class="strain" *ngFor="let strain of chamber.strains; let index = index" formArrayName="strains">-->
        <article class="strain" *ngFor="let strain of chamber.strains; let i = index" formGroupName="i">

The examples I found all use the Formbuilder:

But don't show how define a form with a formArray. Or is the FormBuilder required to do this?

1
Hi, they also use formBuilder, so is it just possible with formBuilder (and not with the syntax new FormArray()?Andi Giga

1 Answers

1
votes

Problem is solved by changing formGroupName to [formGroupName] (with parenthesis)