【发布时间】:2021-11-08 13:16:18
【问题描述】:
我有多个复选框,但我希望用户选择一个复选框而不是多个复选框,如果他选中一个复选框并返回选中值,否则什么都不会显示。有人可以帮忙吗?
<div class="form-check" *ngFor="let product of DisplayProductList">
<label class="form-check-label text-break">
<input class="form-check-input" type="checkbox" [value]="true" [(ngModel)]="product.isChecked"
(change)="changeSelection($event)" />
{{ product.template_name }}
<span class="form-check-sign">
<span class="check"></span>
</span>
</label>
</div>
changeSelection(event: any) {
this.checkedIDs = [];
if (event.target.checked) {
this.selectedItemsList = this.DisplayProductList.filter(
(product, index) => {
if (product.isChecked == true) {
let splitstring = product.template_parameter;
let sepratedArray = splitstring.split(',');
this.variable1 = sepratedArray[0];
this.variable2 = sepratedArray[1];
this.checkedIDs.push(product.id);
this.sendclusteridApi(this.productid);
return product.isChecked;
}
}
);
}
}
【问题讨论】:
-
通常,这就是单选按钮的用途。
-
是的,我们可以为复选框做到这一点。
-
为什么不使用单选按钮?有什么特别的原因吗?