Database provider switch page after promise has ended

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:

teams: ReplaySubject<Team[]> = new ReplaySubject<Team[]>(1);

constructor(storage: Storage) {
  storage.get("teams").then((teams) => {
    this.teams.next(teams);
  });
}

App component:

constructor(data: DataService) {
  data.teams.subscribe((teams) => {
    if (teams && teams.length > 0) {
      this.rootPage = DashboardPage;
    } else {
      this.rootPage = InitializationPage;
  });
}

This idiom extends naturally to retrieving information using Http from a backend server as well.

Thanks. I will try to get this working.