I am practicing ionic to clarify concepts. In this case the promises.
I have an app with 2 pages login and home.
I want a user to validate the login, if it exists, redirect me to the home page. Otherwise stay in the form on the same page.
This validation I am doing in the ionViewWillEnter method of the login page, where I look for user data in SQLite.
The problem is that the validation is not done, the rest of the code is still running before the promise ends. I hope to give me to understand.
When I start the app, this does not work. But if I enter data in the login and go to home, and then return to the login, this works.
I think the problem is the so-called asynchronic of the promise, but how to control it so that it ends and only then the rest is still being executed.
Thank you very much already.
Code example of how I am posing:
public mensaje: string;
ionViewWillEnter(){
this.dbServiceProvider.getUser().then(
(data) => {
this.mensaje = "Ejecuto";
},
(err) =>{
this.mensaje = "Error";
}
).catch(
(ex) => {
this.mensaje = "Excepcion";
});
}
Test code, when you start the app (in the login screen), the text is not displayed ... after login login to Home, back again to the login screen and then if the text is displayed. Why?