我有一個複選框,我可以檢查並顯示一個提示,詢問他們是否確實知道。所以當他們同意警報時,所有的練習都會完成。在選中的複選框上只顯示一次提醒
問題:我設置一個本地存儲物品didAllExercises
所以當我重新打開應用程序,我得到這個項目,如果這是真的不是設置複選框事實,但我對我的複選框,有一個(onChange) event
,如果選中該複選框檢查比顯示警報。因此警報顯示每次當我重新打開應用程序和didAllExercises
項目是真正
這裏是複選框:<ion-checkbox checked="false" [(ngModel)]="cheatCheckbox" (ionChange)="cheatButton(cheatCheckbox)"></ion-checkbox>
這是我cheatButton()
:
cheatButton(cheatCheckbox: boolean){
if(cheatCheckbox){
localForage.setItem("showAlert", true);
console.log('ccTrue', cheatCheckbox);
//DONT SHOW ALERT WHEN ALLEX ARE DONE AND YOU CLOSE AND OPENS THE APP AGAIN AND NAVIGATE TO OEFENINGEN
setTimeout(() => {
localForage.getItem("showAlert", (err, value) => {
if(value){
this.showAlert = value;
console.log('!notRun', value);
}
})
},400)
setTimeout(() => {
let alert = this.alertCtrl.create({
title: 'Voltooi alle oefeninen',
message: 'Weet je zeker dat je alle oefeningen gedaan hebt?',
buttons: [
{
text: 'Nee',
role: 'cancel',
handler:() => {
console.log('Cancel clicked');
this.cheatCheckbox = false;
}
},
{
text: 'Ja ik weet het zeker!',
handler:() => {
this.allExercisesDone = true;
localForage.setItem('didAllExercises', [true, this.data]);
}
}
]
});
alert.present();
},400)
}
}
在這裏,我所說的getItem method
在ionViewWillEnter
:
localForage.getItem('didAllExercises', (err, value) => {
if(value){
this.cheatCheckbox = true;
}
})
如何解決此問題只顯示警告一旦你點擊它,並重新打開應用程序設置複選框爲true,而不顯示相同的警報?
你是說在'localForage.getItem'中設置'this.cheatCheckbox = true;'會觸發你的'cheatButton'函數嗎? – Ari
@Ari yes「cheatButton」函數被真正的 – Sreinieren