Wait Time localstorage

0

I am working on an app in ionic 3 and when doing the login you must load several variables in the localStorage to use in the home, the problem I have is that after passing the login it enters the home quickly and does not load anything because the variables in the localstorage take a second or two to register and when executing the functions in the home, nothing is brought from the localstorage.

What can I do to avoid going to the home if the variables have not yet been loaded by the system.

    
asked by mserradas 12.04.2018 в 20:39
source

1 answer

0

I could give you a more concrete answer if you published what you have done, but I share a solution.

When you use Storage from Ionic, there is a set function to save data, which returns a Pledge , when this promise is resolved, you are sure that the data was saved, At that time you can leave the login page and travel to another.

this.storage.set('name', 'Max'),then(()=>{
  console.log("Dato guardado");
  //Viajo a otra pagina
  this.navCtrl.setRoot('HomePage');
});

Also when you are on your Home page, you should consult the data taking into account the promises.

    
answered by 14.04.2018 в 17:15