Skip to content

Instantly share code, notes, and snippets.

@javebratt
Created September 22, 2016 22:32
Show Gist options
  • Save javebratt/25c8c992267c6aec2ee677c81ed22287 to your computer and use it in GitHub Desktop.
Save javebratt/25c8c992267c6aec2ee677c81ed22287 to your computer and use it in GitHub Desktop.
// Before: When the alert gets called it interrupts the loading component, so it causes a navigation issue:
export class LoginPage {
loginUser(){
this.submitAttempt = true;
if (!this.loginForm.valid){
console.log(this.loginForm.value);
} else {
this.authData.loginUser(this.loginForm.value.email, this.loginForm.value.password).then( authData => {
this.nav.setRoot(HomePage);
}, error => {
let alert = this.alertCtrl.create({
message: error.message,
buttons: [
{
text: "Ok",
role: 'cancel'
}
]
});
alert.present();
});
loading = this.loadingCtrl.create({
dismissOnPageChange: true,
});
loading.present();
}
}
}
// After, we dismiss the loading component and then call the alert, that way it works fine:
export class LoginPage {
loading: any;
loginUser(){
this.submitAttempt = true;
if (!this.loginForm.valid){
console.log(this.loginForm.value);
} else {
this.authData.loginUser(this.loginForm.value.email, this.loginForm.value.password).then( authData => {
this.nav.setRoot(HomePage);
}, error => {
this.loading.dismiss().then( () => {
let alert = this.alertCtrl.create({
message: error.message,
buttons: [
{
text: "Ok",
role: 'cancel'
}
]
});
alert.present();
});
});
this.loading = this.loadingCtrl.create({
dismissOnPageChange: true,
});
this.loading.present();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment