import { App, AlertController, Nav, Platform } from 'ionic-angular';
export class blabla {
@ViewChild(Nav) nav: Nav;
private rootPageToExitOn: string = "TabsPage";
alertShow: boolean = false;
--- in whatever function (It's fine in initializeApp())
this.platform.ready().then(() => {
this.platform.registerBackButtonAction(() => {
let nav = this.app.getActiveNav();
if(nav.canGoBack()) {
nav.pop();
}
else {
let activePage = nav.getActive().instance;
if(this.rootPageToExitOn === activePage.constructor.name) {
if(this.alertShow === false) {
this.alertShow = true;
let alert = this.alertCtrl.create({
title: '',
message: 'Exit?',
buttons: [
{
text: 'Cancel',
role: 'cancel',
handler: () => {
this.alertShow = false;
}
},
{
text: 'Exit',
handler: () => {
this.platform.exitApp();
}
}
]
});
alert.present();
}
}
else {
nav.setRoot(TabsPage);
}
}
});
}
}
Tidak ada komentar:
Posting Komentar
Perhatian! Silahkan berkomentar tanpa ada unsur SARA ^_^