Trying to set limitation for checkbox but not working. If i select more then 2 check box i want to not allow to select. I have tried but not working properly. If anyone knows please help to find the solutions.
mauto.component.ts:
toggleSelection = (data: ItemData): void => {
data.selected = !data.selected;
if (data.selected === true) {
if(this.selectData.length <= 1) {
this.selectData.push(data);
} else {
data.selected = false;
alert("You can select only 2");
}
}
Demo : https://stackblitz.com/edit/angular-ivy-enwmdh?file=src%2Fapp%2Fshared%2Fmauto%2Fmauto.component.ts