jeudi 28 juin 2018

How Can i do Only one checkbox selected at a time in given list in ngFor in angular 5?

I want to do only one checkbox selected at a time in ngFor in angular 5. i have the following code below.

<div class="form-check" style="margin-top:0;">
   <label class="form-check-label">
    <input class="form-check-input"  id="res" (change)="selectRestaurant(restaurant,i)" [checked]="restaurant.checked" type="checkbox">
        <span class="form-check-sign"></span>
    </label>
</div>

And in my component

selectRestaurant(restaurant: any, i: any) {
    if (restaurant) {
      restaurant.checked = !restaurant.checked;
    }
  }

So any possible solution for only one checkbox selected in given list?




Aucun commentaire:

Enregistrer un commentaire