lundi 13 septembre 2021

I want user to select only one checkbox instead of multiple? How can I approach in angular?

I have multiple checkboxes but I want user to select one checkbox but not multiple, if he check one checkbox and it returns checked value, else nothing should show up.can anyone help?

.html

<div class="form-check" *ngFor="let product of DisplayProductList">
                                    <label class="form-check-label text-break">
                                  <input class="form-check-input" type="checkbox" [value]="true"
                                  [(ngModel)]="product.isChecked" (change)="changeSelection($event)"> 
                                  <span class="form-check-sign">
                                    <span class="check"></span>
                                  </span>
                                </label>
                                </div>
.ts
 changeSelection(event: any) {
    this.checkedIDs = []
    if (event.target.checked) {
      this.selectedItemsList = this.DisplayProductList.filter((product, index) => {
       
        if (product.isChecked == true) {
          let splitstring = product.template_parameter
          let sepratedArray = splitstring.split(',');
          this.variable1 = sepratedArray[0];
          this.variable2 = sepratedArray[1];
     this.checkedIDs.push(product.id);
    
         this.sendclusteridApi(this.productid);
          return product.isChecked

        }
       
      }
      );



Aucun commentaire:

Enregistrer un commentaire