Hi everyone,
I have a bit of trouble getting my head around this issue. So in my component.ts I want to check everything in the database once the device is ready. I have managed to do a part of it but I have a condition in which if
- hasSavings() == true and hasPin() == true, my root page becomes the PinCodePage.
- hasSavings() == true and hasPin() == false, my root page becomes the SavingsPage
- hasSavings() == false, automatically the root page becomes the TutorialPage
However, I cannot seem to figure out how to do this.
This is my code:
this.dp.createDatabase().then(data => {
if(data) {
return this.dp.hasSavings();
}else {
return false;
}
}).then(data => {
if(data) {
this.rootPage = SavingsPage;
}else {
this.rootPage = TutorialPage;
}
return this.dp.hasCategory()
}).then(data => {
if(data) {
console.log("Tables already populated.");
return false;
}else {
return this.dp.populateTables();
}
}).then(data => {
console.log("Tables successfully populated!");
}, err => {
console.log("Nope");
})
});
Kinda confused on how to use promises. If I also made some mistakes in implementing them please do enlighten me.
Thank you!