我已经搜索过与此相关的问题,发现人们大多否认它的发生,我检查了我的配置没有用,尝试了一些东西,包括suggestions on this page。
这是我的复选框
<div *ngFor="let customer of customers; let customerIndex=index">
<input type="checkbox" value="on" name="Customer_{{customerIndex}}" [checked]="customer.isSelected" />
</div>
上面的代码运行良好,我在Chrome检查器中看到了下面的代码。
现在,当我将复选框更改为使用双向绑定时
<div *ngFor="let customer of customers; let customerIndex=index">
<input type="checkbox" value="on" name="Customer_{{customerIndex}}" [(ngModel)]="customer.isSelected" />
</div>
Chrome检查器显示
name
属性已消失。如何使用对复选框的双向绑定并保留
name
属性? 最佳答案
尝试[attr.name]="'Customer_' + customerIndex"
而不是name="...