I initialized a FormBuilder and after I put data in it, like the code below:
generateTable(dataJobs: any): void {
this.formBuilder = this.fb.group({
jobs: this.fb.array([
this.fb.group({
name: this.fb.control(null),
operations: this.fb.array([])
})
])
})
this.jobs.removeAt(0)
for (let i = 0; i < dataJobs.length; i++) {
this.jobs.push(this.fb.group({ name: dataJobs[i].name, operations: [dataJobs[i].operations] }))
}
}
I have this method to access jobs
get jobs() {
return this.formBuilder.get('jobs') as FormArray;
}
the value of formBuilder is this:
{
"jobs": [
{
"name": "job0",
"operations": [
"(M0,3)",
"(M1,2)"
]
},
{
"name": "job1",
"operations": [
"(M1,3)",
"(M1,2)"
]
}
]
}
I tried to do the following code in html but I didn't get anything
<table>
<form [formGroup]="formBuilder">
<thead>
<tr class="fw-bolder fs-6 text-gray-800">
<th>#</th>
<th>2</th>
<th>2</th>
</tr>
</thead>
<tbody>
<tr formArrayName="jobs"
*ngFor="let jobs of formBuilder.get('jobs')['controls']; let i=index">
<td formArrayName="operations"
*ngFor="let operations of formBuilder.get('jobs')['controls'][i].get('operations')['controls']; let ind =index">
{{operations}} {{ind}}
</td>
<td>Tiger Nixon</td>
<td>Tiger Nixon</td>
</tr>
</tbody>
</form>
</table>
How can i make the table with formBuilder?