i am trying to create the dynamic reactive form using angular i am able to loop it but it is displaying the exact way
<form [formGroup]="registerForm" (ngSubmit)="onSubmit()">
<div *ngFor="let dat of formData;let index = index;">
<label for="{{dat.name}}">{{dat.name }}</label>
<input type="text" id="{{dat.id}}" [formControlName]="dat.name" />
</div>
</form>
<button type="button"><button>
.ts
registerForm: FormGroup;
submitted = false;
formData = [{ id: 'firstName', name: 'firstName' },
{ id: 'lastName', name: 'lastName' },
{ id: 'address', name: 'address' },
{ id: 'emailid', name: 'emailid' }
]
constructor(private formBuilder: FormBuilder) {
this.registerForm = this.formBuilder.group({
formData: []
});
}
onSubmit(){
console.log(this.registerForm.value);
}
including the validation
below is my stackblitz url
FormArray: angular.io/guide/reactive-forms If you encounter problems come back and ask :)