I'm currently battling with Angular form array.
I have a form in which I add the fields dynamically.
I have created the form object:
this.otherDataForm = this.fb.group({
});
I add the dynamic fields like this:
addField(field: CustomFormField): void {
this.otherDataForm.addControl(id_campo, new FormControl('', Validators.required));
}
I loop through those fields:
<form *ngIf="selectedProfile" [formGroup]="otherDataForm">
<div class="mb-3" *ngFor="let field of fields; let i = index">
<label>{{field.descripcion}}</label>
<input class="form-control" [formControlName]="field.id_campo" type="number">
</div>
</form>
But I can't seem to get control of the errors of each field to show a validation message if the field is required.
Anyone can help me with this one? Maybe there is a better way to do this.