Nav.pop() in ActionSheet doesn't work


#1

Maybe I’m missing an extra step for a nav pop to work in my action sheet, but this is what I’ve got:

presentActionSheet(id) {
let actionSheet = ActionSheet.create({
  title: 'You wanna delete. Really?',
  buttons: [{
    text: 'Delete',
    role: 'destructive',
    handler: () => {
      console.log('This will delete', id);
      this.service.deleteCategory(id)
        .then(data => {
          console.log('Successful ->', data.res) // this logs
          this.displayToast(); // this shows
          this.nav.pop(); // this? not so cooperating
        }, error => {
          console.log('Error ->', data.err);
        })
    }
  }, {
    text: 'Cancel',
    role: 'cancel',
    handler: () => {
      console.log('Cancelled');
    }
  }]
});
this.nav.present(actionSheet);

}

As my inline comments indicate, displayToast() and the console log works. All is fine, except the navigation doesn’t pop the current view.

Just to clarify, when the handle is called, it actually deletes the category with that id, just doesn’t navigate away.

Something I need to do?


#2

Check out the ActionSheet API docs for Dismissing And Async Navigation. Basically, you have to wait for the dismiss transition to end before calling the transition to pop. Although, I’m not sure what displayToast is doing so this may need to be tweaked for your use case.

let actionSheet = ActionSheet.create({
  title: 'Hello',
  buttons: [{
    text: 'Ok',
    handler: () => {
      // user has clicked the action sheet button
      // begin the action sheet's dimiss transition
      let navTransition = actionSheet.dismiss();

      // start some async method
      someAsyncOperation().then(() => {
        // once the async operation has completed
        // then run the next nav transition after the
        // first transition has finished animating out

        navTransition.then(() => {
          this.nav.pop();
        });
      });
      return false;
    }
  }]
});

this.nav.present(actionSheet);

#3

when i run that code i get an error saying

browser_adapter.js:77 ORIGINAL EXCEPTION: ReferenceError: someAsyncOperation is not defined

so why is that?


#4

The someAsyncOperation function is just an example

You can also use the snippet below:

let actionSheet = ActionSheet.create({
title: ‘Hello’,
buttons: [{
text: ‘Ok’,
handler: () => {
actionSheet.dismiss().then(() => {
this.nav.pop();
});
return false;
}
}]
});

this.nav.present(actionSheet);