exit application after showing ionic popup

242 views Asked by At

I have this code in my application:

$ionicPopup.alert({
    title: $scope.header1,
    template: 'The was a problem connecting to the server.  Please check your internet connection and try again.'
});
ionic.Platform.exitApp() 

what I have noticed is that in Android, the application exits quickly without showing the pop up message. What I wanted to do is execute

ionic.Platform.exitApp() 

after the user press the 'Ok' button in the pop-up. ls there something like an "onleave" event in ionic Popup?

1

There are 1 answers

0
Stevangelista On

The best approach may be to define your own 'OK' button as opposed to leveraging the default dismiss one - that way you can invoke ionic.Platform.exitApp() upon the user clicking/tapping your button.

Example:

import { AlertController } from 'ionic-angular';

constructor(private alertCtrl: AlertController) {

}

presentAlert() {
  let alert = this.alertCtrl.create({
    title: YourCustomHeader,
    //subTitle: 'optional text',
    message: 'The was a problem connecting to the server.  Please check your internet connection and try again.',
    buttons: [
      {
        text: 'OK',
        handler: () => {
          ionic.Platform.exitApp();
        }
      }
    ]
  });
  alert.present();
}

Reference: https://ionicframework.com/docs/api/components/alert/AlertController/#usage