lundi 14 mai 2018

Disable checkbox after clicking button on ionic

I'm making an Ionic app and I'm creating profiles grups on it. To do this, the user needs to choose profiles from a checkbox list, then click a button and the group is created. At this point, those profiles already selected should disappear or at least should be unable to click them, but I can't do it. Code: HTML

<ion-list>
  <ion-item *ngFor="let profile of profiles; let i = index">
     <ion-label></ion-label>
     <ion-checkbox color="dark" [(ngModel)]="values[i]"></ion-checkbox>
  </ion-item>
</ion-list>
<button ion-button full (click)="addGroup()">Add group</button>

TS

profiles = [];
values = [];
groupList = [];

addGroup(){
let y=0;
for(let i=0; i<this.values.length; i++){
  if(this.values[i] == true){
    this.groupList[y] = this.profiles[i];
    y++;
  }
}
let alert = this.alertCtrl.create({
  title: 'Group created!',
  buttons: ['OK']
});
alert.present();

//I tried this to solve the problem, but it is not really what I want...
for(let i=0; i<this.values.length; i++){
  if(this.values[i] == true){
    this.profiles[i] = 0;
  }
}
}




Aucun commentaire:

Enregistrer un commentaire