I have created dynamic form inputs in angular11. need to validate the form fields which added dynamically by clicking add button. i couldnt found the right solutions. here is my code
in component.ts file
this.pollAdd = this.fb.group({
question: ['',Validators.required],
queChoices:this.fb.array([this.createChoice()]),
});
addChoice(){
this.queChoices=this.pollAdd.get('queChoices') as FormArray;
this.queChoices.push(this.createChoice());
}
createChoice():FormGroup{
return this.fb.group({
choice:['',Validators.required],
})
}
get f() { return this.pollAdd.controls; }
In component.html file
<div formArrayName="queChoices" *ngFor="let choices of pollAdd.get('queChoices')['controls'];let i=index;">
<mat-form-field class="ch__custom_input w-100 mt-3" [formGroupName]="i">
<mat-label>Choice {{i+1}}</mat-label>
<input matInput formControlName="choice" autofocus/>
</mat-form-field>
</div>
how to validate each choice field?