I am working with an array of items in Angular, using ngFor to display a list of checkboxes. I need to implement validation that ensures at least one checkbox remains mandatory.
For example, if one checkbox is checked and another is unchecked, I want to prevent unchecking the checked box. Only when the unchecked box is selected, should the previously checked box be enabled.
Here is what I have attempted:
<div *ngFor="let item of dataList"\>
<input type="checkbox" [checked\]="item.checked" (change)="itemSelected($event, item)" [disabled]="notSelectCheck">
itemSelected(value, level ) {
level.checked = value.target.checked
const valuesChecked = this.dataList.filter((dt) =\> dt.checked).length;
valuesChecked \< 2 ? (this.notSelectCheck = true) : (this.notSelectCheck = false)
}