how do i select only one checkbox at a time in angular 9?

This happening because, you’re using same ngModel for all checkbox, that will bind the value(boolean) to all inputs automatically, which is resulting selecting all. To fix this, you should be using separate ngModel for each checkbox.

Example: link

// component.
ChooseCriteria = [
  { category: "Fruits", id: 1, checked: false },
  { category: "Animals", id: 2, checked: false }
];

<div>
 <span>{{ ChooseCriteria | json }}</span>
 <label for=" Option" *ngFor="let mc of ChooseCriteria" class="form-control" > 
  <input type="checkbox" name="Option" [(ngModel)]="mc.checked"> 
  {{ mc.category }}
 </label>
</div> 

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top