I am having a checkbox inside a for loop and having a array to store the row details. I only wants to select two checkboxes at a time. when a user clicked on the 3rd checkbox, checkbox should be unchecked automatically while giving a toaster messege.
I have tried to implement this and am getting the toaster messege successfully. But 3rd checkbox is not getting unchecked automatically. Please help on this.
HTML
<tr *ngFor="let row of rows$; let indexOfEl = index">
<td><input type="checkbox" value="indexOfEl (change)="onCheckboxChange($event,indexOfEl,row)"/></td>
</tr>
TS file
onCheckboxChange(event: any, index:any, data: any){
if(event?.target?.checked){
if(this.selectedCommand.length < 2){
data.index = index;
this.selectedCommand.push(data);
}
else {
this.sharedService.showErrorNotification('Cannot select more than two commands', 'Error');
}
}
else this.selectedCommand = this.arrayRemove(this.selectedCommand,index);}
arrayRemove(array:any , index:any){
return array.filter(function(element){
return element.index != index;
});
}