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

ionViewWillLeave Cancel Navigation

$
0
0

@alokjkumar97 wrote:

I have a view with a form and an ion-back-button. I’d like to show an alert box which warns the user that their changes will not be saved when they select the back button. If they choose to cancel, is it possible to cancel the navigation at that point?

Something like this…

ionViewWillLeave() {

  if(this.formGroup.dirty) {
    const alert = await this.alertController.create({
      header: 'Confirm!',
      message: 'If you navigate away from this page, your changes will not be saved. Please press "Save" to save your changes.',
      buttons: [
        {
          text: 'Cancel',
          role: 'cancel',
          cssClass: 'secondary',
          handler: () => {
            // Cancel navigation
          }
        }, {
          text: 'Okay',
        }
      ]
    });

    await alert.present();
  }
}

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70434

Trending Articles



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