I want to create form with a form array. But I get the failure
Cannot find control with path: 'strains -> i'
But my strainsForm
contains 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:
- https://angular.io/guide/reactive-forms
- https://angularfirebase.com/lessons/basics-reactive-forms-in-angular/
- https://alligator.io/angular/reactive-forms-formarray-dynamic-fields/
But don't show how define a form with a formArray
. Or is the FormBuilder required to do this?
new FormArray()
? – Andi Giga