Reputation: 35
I have this function in my Ionic App:
clearTransactions() {
this.clearIndex = this.clearIndex + 1;
if (this.clearIndex < 3) {
console.log("click " + (3 - this.clearIndex) + " more times");
} else {
this.storage.clearItems()
this.storage.getItems().then(
items => {
this.items = items
console.log("test", this.items);
}
)
this.clearIndex = 0;
}
}
For some reason, the this.storage.getItems() runs even before the this.storage.clearItems() finish. Can anyone suggest a solution for this problem? Thanks!
Upvotes: -1
Views: 309
Reputation:
clearItems returns a promise and you have run the rest of the code when it's finished like this:
this.storage.clearItems().then(()=>{
// do things after clear
})
Upvotes: 1