I have a table that is dynamically created and it displays data as follows:
<table>
<tr *ngFor="let product of products">
<td>{{product.name}}</td>
<td>{{product.description}}</td>
<td>{{product.value}}</td>
<!-- BELOW IS WHERE A NEW VALUE WILL BE ENTERED -->
<td><input type="text" value=""></td>
</tr>
</table>
I've read that the appropriate way of handling this is with a FormsArray. But I've also read that the appropriate way of using a FormsArray is to grab its array of controls:
<table>
<tr *ngFor="let product of this.form.get('productCollection').controls; let i = index;"
[formGroupName]="i">
<td>{{product.name}}</td>
<td>{{product.description}}</td>
<td>{{product.value}}</td>
<!-- BELOW IS WHERE A NEW VALUE WILL BE ENTERED -->
<td><input type="text" formControlName="name"></td>
</tr>
</table>
The problem is that I don't have access to the description value here. And I haven't found a way to pass this as metadata to the control so I can show it.
So the question is for something like this, which is the correct approach? Is it FormArray? Is it an array of FormControls in one FormGroup? Or does each formcontrol need to be by itself? I'm open to suggestions on how to make this work.