Hello there,
I’m trying to learn more about ionic, starting with the basics by creating a list of checkboxes. It’s a reading app and the user will be able to select which content he does and doesn’t want to see. Right now, this is the code for the checkbox list:
<ion-content padding>
<ion-list>
<ion-item>
<ion-label>Jon Snow</ion-label>
<ion-checkbox [(ngModel)]="cucumber" (ionChange)="updateChecklist()"></ion-checkbox>
</ion-item>
<ion-item>
<ion-label>Daenerys Targaryen</ion-label>
<ion-checkbox color="dark" checked="true"></ion-checkbox>
</ion-item>
</ion-list>
</ion-content>
Whenever the user click on “Jon Snow”, my .ts does:
checklist: boolean = false;
var:string;
updateChecklist() {
this.storage.set('name', 'John').then(() => {
if (this.checklist){
this.checklist = false;
this.storage.set('state', 'false');
} else {
this.checklist = true;
this.storage.set('state', 'true');
}
this.storage.get('state').then((val) => {
this.var = val;
console.log(this.var);
});
});
}
What I want to do is to set Daenerys Targaryen:
<ion-item>
<ion-label>Daenerys Targaryen</ion-label>
<ion-checkbox color="dark" checked="true"></ion-checkbox>
</ion-item>
Based on the ‘state’ on storage.
What I tried to do is create a second function:
getState (){
return this.storage.get ('state');
}
and use it like this:
<ion-item>
<ion-label>Daenerys Targaryen</ion-label>
<ion-checkbox color="dark" checked="getState ()"></ion-checkbox>
</ion-item>
But that’s not working, how can I get a value from storage and use it to check my checkboxes whenever I go to this pages or on the app start?
When I click on Jon snow my console is:
console.log: true
and console.log: false
, etc.
Thank you!