Using ngModel
in Angular 5, I have the following Html
:
<span *ngFor="let id of Ids">
<input class="checkbox" type="checkbox" [(ngModel)]="strManyModel[id]" (change)="setValue($event)" [value]="id">
</span>
And here is the corresponding TypeScript
:
setValue(e){
if(selectedChkBox > 5){
this.strManyModel[e.target.value] = false;
}
}
I am trying to limit the number of checkboxes that can be selected to 5. Currently, once 5 are selected, any additional selections are allowed. However, I want to restrict checkbox selection after 5 have been checked. Users should only be able to select up to 5 checkboxes at a time. If they try to check another one after selecting 5, they must first uncheck one of their previous selections.