[英]How to disable all other checkboxes inside ngfor when I select a checkbox?
I have list of item inside table for each item I'm enabling a checkbox to edit and delete values.对于每个项目,我都有一个项目列表,我启用了一个复选框来编辑和删除值。 But I can select only 1 checkbox at time when selected others should be disabled.
但是我可以 select 在选择其他应禁用时仅 1 个复选框。
<tr *ngFor="let lists of resObj;let i = index">
<td>
<label class="check-box-block">
<input type="checkbox" (change)="selectBox($event, lists, lists.id,i)" id="checkBox"
[disabled]="chk" />
<span class="checkmark"></span>
</label>
</td>
</tr>
selectBox(event,list, id, i)
{
if (event.target.checked) {
this.chk = true;
this.checkedArray.push(list);
} else {
this.chk = false;
const newArr = this.checkedArray.filter(item => item !== list);
this.checkedArray = newArr;
}
}
}
you can use a variable "select" and use some like您可以使用变量“选择”并使用一些类似
<input type="checkbox" [checked]="select==i" (change)="select=select==i?-1:i">
NOTE: I don't understand that "selected others should be disabled " (I suppose you want to say unchecked )注意:我不明白“选择的其他人应该被禁用”(我想你想说unchecked )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.