gpt4 book ai didi

angular - ngModel 总是将最后一项复制到表中的所有字段

转载 作者:行者123 更新时间:2023-12-04 00:05:15 26 4
gpt4 key购买 nike

我有这个数组试图在我的模板中显示,不知何故它无法正确显示。如果我这样做 [value],它将给我正确的值,但 ofc。不绑定(bind)到数组和值。

大批:

{"pluNo":1,"pluName":"Smirnoff 2cl","pluDepartment":"VODKA","pluPrice":2000},
{"pluNo":2,"pluName":"Smirnoff 4cl lala","pluDepartment":"VODKA","pluPrice":4000},
{"pluNo":3,"pluName":"Jack D 2cl","pluDepartment":"Whiskey","pluPrice":2200},
{"pluNo":4,"pluName":"Smirnoff 4cl","pluDepartment":"VODKA","pluPrice":4000},
{"pluNo":5,"pluName":"Rom","pluDepartment":"Rom","pluPrice":2500},
{"pluNo":6,"pluName":"Rom 4cl","pluDepartment":"Rom","pluPrice":5000}

这是我的表格,PLU 编号打印正确,只有其他字段都设置为我列表的最后一项。
<tbody>
<tr *ngFor="let item of products; let i = index">
<td scope="row">
{{item.pluNo}}
</td>
<td>
<input type="text" [(ngModel)]="item.pluName" name="plu" class="form-control m-input" placeholder="" value="">
</td>
<td>
<input type="text" [(ngModel)]="item.pluDepartment" name="pluDepartment" class="form-control m-input" placeholder="" value="">
</td>
<td>
<input type="number" [(ngModel)]="item.pluPrice" name="pluPrice" class="form-control m-input" placeholder="">
</td>
<td>
<button (click)="deletePluItem(item)">Delete</button>
</td>
</tr>
</tbody>

最佳答案

您需要做的就是提供不同的name致所有 inputs

更改 name="plu"name="plu{{i}}"
并检查,您将了解该问题,然后对所有输入进行更改。

关于angular - ngModel 总是将最后一项复制到表中的所有字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48945025/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com