Checkbox is returning undefined if not marked, and checked doesn't work

I have a checkbox like this:

    <ion-label>Essa atividade já foi feita</ion-label>
    <ion-checkbox dark checked="true" [(ngModel)]="statusTarefa"></ion-checkbox>

However, checked="true" doesn’t work, since the checkbox appears unchecked. And if the user doesn’t check and uncheck, it retuns undefined as value. I tried setting checked="false" but still returns undefined.


Do the following:

In the view html:

<ion-checkbox dark [checked]=true [(ngModel)]="statusTarefa"></ion-checkbox>

ts file:
//Initialize the statusTarefa to true in the constructor as below
export class HomePage {
statusTarefa : boolean;
constructor(public navCtrl: NavController) {
this.statusTarefa = true; //initialize to default value

1 Like