【发布时间】:2019-07-23 23:04:26
【问题描述】:
我有一个动态创建的表,它显示数据如下:
<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>
我已经读到处理这个问题的适当方法是使用 FormsArray。但我也读到了使用 FormsArray 的适当方法是获取它的控件数组:
<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>
问题是我无法访问此处的描述值。而且我还没有找到一种方法将它作为元数据传递给控件,以便我可以显示它。
所以问题是这样的,正确的方法是什么?是表单数组吗?它是一个 FormGroup 中的一组 FormControls 吗?还是每个表单控件都需要单独存在?我愿意接受有关如何完成这项工作的建议。
【问题讨论】:
标签: angular dynamic-forms reactive-forms formarray formgroups