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

I have a checkbox like this:

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

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.

image

Do the following:

In the view html:

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

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