[英]Angular 4: use of ngModel two-way binding instead of [checked] gets rid of the 'name' attribute
I have searched through existing questions related to this and have found people mostly denying it happening, I checked my configuration to no avail, tried several things including suggestions on this page . 我搜索了与此相关的现有问题,发现大多数人都否认这种情况的发生,我检查了我的配置无济于事,尝试了包括此页建议在内的几项工作。
Here is my checkbox 这是我的复选框
<div *ngFor="let customer of customers; let customerIndex=index">
<input type="checkbox" value="on" name="Customer_{{customerIndex}}" [checked]="customer.isSelected" />
</div>
The above code works fine and I see the following in Chrome inspector. 上面的代码工作正常,我在Chrome检查器中看到以下内容。
Now when I change my checkbox to use two-way binding like so 现在,当我更改复选框以使用双向绑定时,如下所示
<div *ngFor="let customer of customers; let customerIndex=index">
<input type="checkbox" value="on" name="Customer_{{customerIndex}}" [(ngModel)]="customer.isSelected" />
</div>
The Chrome inspector shows that the name
attribute is gone. Chrome检查器显示
name
属性已消失。
How do I use two-way binding to my checkbox and preserve the name
attribute? 如何使用双向绑定到我的复选框并保留
name
属性?
尝试使用[attr.name]="'Customer_' + customerIndex"
代替name="...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.