vendredi 24 mars 2017

How To check If My List Of Checkbox is Checked or Unchecked AngularJS 2

I have a list of checkbox.

documentType: IDocument[] = [
    {
      "type": "A",
      "checked": false,
    },
    {
      "type":"B",
      "checked": false,
    },
    {
      "type":"C"    ,
      "checked": false,
    }];

I display this array in a list of checkbox on the template :

<ion-list *ngFor="let type of documentType">
  <ion-item >
   <ion-label></ion-label>
       <ion-checkbox [(ngModel)]="type.checked"            (click)="checkBoxChecked(type.documentTypeName)" disabled="false" ></ion-checkbox>
  </ion-item>
</ion-list>

back to the component i created the checkBoxChecked method:

  checkBoxChecked(documentTypeinput)
  {
    if (documentTypeinput =="A")
    {
      console.log("this A");
    }
    else if (documentTypeinput=="B"){
      console.log("B")
    }
    else if (documentTypeinput=="C"){
      console.log("C")
    }
  }

But this is not the appropriate way. i can't know what element is checked or unchecked. Can you help me to figure out the best practice to work with multiple checkboxs. because i want to set the array with services. and i want my code reusable. so i will change only the web api. thank you in advance




Aucun commentaire:

Enregistrer un commentaire