Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70779

AlertController is not presenting more than once in a page

$
0
0

@pa1b wrote:

Hi,
I’m trying to use hardware back button to exit from the app and have written the below code for it.

//imports
import { AlertController } from '@ionic/angular';
import { Plugins } from '@capacitor/core';

const { App } = Plugins;

//listener for backbutton
ngOnInit() {
    App.addListener('backButton', () => {
        this.alertCtrl.create({
          header: 'Exit App',
          message: 'Do you want to exit the app?',
          buttons: [
            {
              text: 'No',
              role: 'cancel'
            },
            {
              text: 'Yes',
              handler: () => {
                App.exitApp();
              }
            }
          ]
        }).then((alertEl) => {
          alertEl.present().then(() => {
             console.log('present');
          });
        });
      }
    });

`
Whenever hardware back button is hit while in home page, an alert must be presented to exit app or not.
The above code is working for the first the page is entered, that is the alert is presented, if Yes is clicked the app is exited, and if No, the alert is dismissed. But after dismissing the alert, the alert is not being presented.

The console log present is not being logged.
I tried replacing ngOnInit with ionViewWillEnter, but the result did not change.

Any help? Did anyone face this kind of issue?

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70779

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>