【发布时间】:2018-11-16 16:57:13
【问题描述】:
我有一个绑定到我的组件打字稿文件中的对象的复选框列表,我希望它在用户单击复选框时选中/取消选中列表,但由于某种原因,它只选中并取消选中列表上的第一个复选框,而不是用户单击的复选框。 下面是代码:
<div>
<ul class="reports-container">
<li *ngFor="let item of data.reports" [class.active]="selectedReport==item" >
<input type="checkbox" id="{{'savedreport'+i}}" class="k-checkbox" [checked]="item.IsSubscribed" [value]="item.IsSubscribed"(change)="onChkBoxChange($event,item)" />
</li>
</ul>
</div>
这里是打字稿功能:
onChkBoxChange(event, item: SavedReport) {
item.IsSubscribed = event.target.checked;
}
当我放置一个断点时,它总是在列表中的第一项中传递,有什么想法吗?
【问题讨论】:
-
抱歉之前的回答,我误会了。您只是希望复选框的值正确绑定到 item.IsSubscribed,对吗?为什么不使用双向绑定?
[(value)] = "item.IsSubscribed" -
不用担心,这是一个很好的点,不知道我怎么没想到,谢谢!
标签: html angular typescript checkbox