I'm trying to build a dynamic form, where the field names and their validations will come from an API
so I'm creating a simple form, with a formArray inside, something like this:
this.myForm = this.formBuilder.group({
dynamicFields: this.formBuilder.array([]) // where I will be pushing the custom fields and their validations
});
Just for testing, I'm trying to add a field 'country', with 2 validations (required, minLength of 22)
this is what I'm doing:
let customControl = this.fb.control('country', [ Validators.required, Validators.min(10) ]);
(this.myForm.get('dynamicFields') as FormArray).push(customControl);
I also created the bellow getter to use it in my template
getDynFields() {
return this.myForm.get('dynamicFields') as FormArray;
}
and this is the template:
<form [formGroup]="myForm">
<div formArrayName="dynamicFields">
<div *ngFor="let control of getDynFields().controls; let i = index">
<mat-form-field>
<input
[formControlName]="i"
matInput
type="text"
placeholder="{{ control.value }}"
/>
</mat-form-field>
</div>
</div>
</form>
what is happening (as you see below) is that for the field value and placeholder I'm getting 'country' pre-populated (I only want the placeholder to be 'country' and the value should be empty of course) And the second issue is that only required validation is working, minLength is not doing anything
Thanks in advance.

<mat-error>. Secondly you should replacemin()withminLength()