My method file1.ts
create(cad) {
this.service.postData(cad.value)
.subscribe((data) => {
this.callAlert(data);
});
}
I want to call alert method
callAlert(data) {
if(data) {
let alert = this.alertCtrl.create({
title: 'Success!',
subTitle: 'Successfuly',
buttons: ['Ok']
});
alert.present();
} else {
this.navCtrl.push(Login).catch( err => {
let alert = this.alertCtrl.create({
title: 'Ops!',
subTitle: 'Houve algo de errado',
buttons: ['Ok']
});
alert.present();
});
}
and redirect to any page (Login Page) -> example
But doesn’t work please
No errors? I assume these 2 pieces of code are in the same class?
I would something simple see you:
registe(data) {
if(data){
//call alert method and redirect to another page ???
}
}
showAlert() {
this.alert = this.alertCtrl.create({
title: 'Titulo aqui',
subTitle: 'Subtitulo aqui para teste vamos ver no que vai dar',
buttons: ['Ok']
});
this.alert.present();
}
only that
Assuming I understand correctly, here’s my 2 examples
Alert and redirect
registe(data) {
if(data){
this.showAlert();
this.navCtrl.push(PageComponent);
// or
this.navCtrl.setRoot(PageComponent);
}
}
showAlert() {
this.alert = this.alertCtrl.create({
title: 'Titulo aqui',
subTitle: 'Subtitulo aqui para teste vamos ver no que vai dar',
buttons: ['Ok']
});
this.alert.present();
}
Alert then redirect
registe(data) {
if(data){
this.showAlert().then(() => {
this.navCtrl.push(PageComponent);
// or
this.navCtrl.setRoot(PageComponent);
});
}
}
showAlert() {
return new Promise(resolve => {
this.alert = this.alertCtrl.create({
title: 'Titulo aqui',
subTitle: 'Subtitulo aqui para teste vamos ver no que vai dar',
buttons: ['Ok']
});
this.alert.present();
this.alert.onWillDismiss(() => resolve);
});
}
Someting along these lines