Hi, I’m new to Ionic2 and I have a problem regarding my Database provider which has a promise to get data from the database. How can I switch pages after this promise is resolved?
data.ts:
constructor() {
console.log('DataDB started');
this.storage.get("teams").then((val) => {
console.log(val);
if(val != null){
this.teams = JSON.parse(val); //Now the teams are initialized, go to the other page?? How?
this.idTeamCounter = this.teams.length;
} else {
this.teams = [];
this.idTeamCounter = 0;
}
});
}
You have a couple of decent options here, but it all boils down to exposing an Observable in this data provider and subscribing to it somewhere (probably the app component). That Observable can either expose that teams array directly (my preferred option) or simply a boolean indicating whether or not we have the teams loaded. Something like so: