alert not able to dismiss after action sheet

Ionic version 3.19.0

Try to popup a confirm alert after click on action sheet button, but there is a bug won’t let confirm alert to close after button click or click on out side of container.

here is how to fix.

1. we have to create a function for confirm alert

presentConfirm() {
  let alert = this.alertCtrl.create({
    title: 'Confirm purchase',
    message: 'Do you want to buy this book?',
    buttons: [
      {
        text: 'Cancel',
        role: 'cancel',
        handler: () => {
          console.log('Cancel clicked');
        }
      },
      {
        text: 'Buy',
        handler: () => {
          console.log('Buy clicked');
        }
      }
    ]
  });
  alert.present();
}

2. Create action sheet function

presentActionSheet() {
   let actionSheet = this.actionSheetCtrl.create({
     title: 'Modify your album',
     buttons: [
       {
         text: 'Destructive',
         role: 'destructive',
         handler: () => {
           let closeSheetOpenConfirm = presentConfirm.dismiss();
              closeSheetOpenConfirm.then(() => {
                  this.mergeConfirm();
               });
        return false;
         }
       },
       {
         text: 'Archive',
         handler: () => {
           console.log('Archive clicked');
         }
       },
       {
         text: 'Cancel',
         role: 'cancel',
         handler: () => {
           console.log('Cancel clicked');
         }
       }
     ]
   });

   actionSheet.present();
 }

ok the secret is the code

let closeSheetOpenConfirm = presentConfirm.dismiss();
              closeSheetOpenConfirm.then(() => {
                  this.mergeConfirm();
               });
        return false;

this mean we have to close actionsheet first, and then open up confirm alert. so confirm alert are able to close, otherwise there will be two box open up, so the code dismiss are didn’t know which to close.

 

Leave a Reply

Your email address will not be published. Required fields are marked *