Hey ! I have a JSON URL from which some data is coming, I am getting that data in Checkbox. The problem is that how to get data (values selected) from ion-checkbox ?
Thanks
Use ngModel for that maybe, it’s what you want ?
@Dlazzy i am using ngModel but its not getting the values of all selected checkboxes. Moreover how can i restore multiple values in 1 ngModel.
@pendora7 Can you show some code ?
@Dlazzy here i want to get value of every selected checkbox…
But for now your code does not add already ‘selected’ checkbox ?
modify your ion-checkbox like this:
<ion-checkbox *ngIf="tost.qotext != ''" (ionChange)="getChanged(tost.qotext)" ></ion-checkbox>
And then in your ts file:
export class DemoPage{
selectedCheckbox: any;
constructor() {
this.selectedCheckbox = {};
}
getChanged(e){
if(!this.selectedCheckbox[e])
{
this.selectedCheckbox[e] = true;
}
else{
this.selectedCheckbox[e] = false;
}
console.log(this.selectedCheckbox);
}
}
You’ll get all your selected checkbox in json with true value.( check variable this.selectedCheckbox)