How can I determine if a ion-checkbox is checked in Ionic 2.
<ion-item *ngFor="let a of q.Answers">
<ion-label>{{a.AnswerDescription}}</ion-label>
<ion-checkbox (click)="addValue($event)"></ion-checkbox>
</ion-item>
the following return undefined
addValue(e): void {
var isChecked = e.currentTarget.checked;
console.log(isChecked);//undefined
}
var chk1 = document. getElementById("isChecked1"); var chk2 = document. getElementById("isChecked2"); chk1.
The Ionic checkboxes are styled differently on each platform as like other Ionic components. You can use checked attribute with the <ion-checkbox> element to set the default value, and disabled attribute to disable the user from changing the value.
Use e.checked property if you really wanted to pass $event as an argument as shown below.
HTML
<ion-checkbox color="dark" checked="true" (ionChange)="datachanged($event)" ></ion-checkbox>
TYPESCRIPT
datachanged(e:any){
console.log(e);
console.log(e.checked);
}
Just use an NgModel
<ion-checkbox checked="false" [(ngModel)]="yourVariable.checked"></ion-checkbox>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With