I have a table which dynamically constructs rows as follows
<form [formGroup]='employeeForm'>
<table class="table table-dark">
<thead>
<tr>
<th scope="col">name</th>
<th scope="col">contact details</th>
</tr>
</thead>
<tbody>
<tr *ngFor='let details of employeeDetails'>
<th formControlName='name' scope="row">{{details.name}}</th>
<td formControlName='employeeName'>{{details.contactDetails}}</td>
</tr>
</tbody>
</table>
</form>
now, how can i attach my dynamically created controls to the form? i tried this
employeeForm: FormGroup
constructor(private formbuilder: FormBuilder) { }
ngOnInit() {
this.employeeForm = this.formbuilder.array([])
}
but it is giving me error stating, the formGroup cannot contain formArray
how can i add my formArray into the formGroup using reactive form approach?
this.formbuilder.array([]). FormBuilder.array() creates and returns a FormArray, not a FormGroup. So this can't possibly be correct. Use arra() to create a FormArray. use group() to create a FormGroup. Read the guides to know what form groups and form arrays are, and how to use them. angular.io/guide/reactive-forms