search

Home  >  Q&A  >  body text

javascript - How does Ionic ask the user for confirmation before returning to the previous page? If the user selects "No", the return operation is canceled and the user remains on the current page?

How does Ionic ask the user before returning to the previous page: The current data has been modified. Do you want to confirm to abandon the modification and return? If the user selects "No", cancel the return operation and remain on the current page?

Writing the code to pop up the inquiry box in the $ionicView.beforeLeave event seems not possible, because when the event occurs, it has already returned to the previous page. And I don’t know how to cancel the default operation of this event. Using event.preventDefault() is invalid.

$rootScope.$on("$ionicView.beforeLeave", function (event, view) {
  $ionicPopup.confirm({
    title: "确认放弃修改",
    template: "数据已经修改,是否确认放弃修改并返回?"
  }).then(function (res) {
    res || event.preventDefault();
  });
});

The above code can pop up the confirmation dialog box, but when it pops up, the page has already slid to the previous page and it pops up too late. And event.preventDefault() is invalid and cannot prevent the page from leaving.

某草草某草草2741 days ago669

reply all(1)I'll reply

  • 漂亮男人

    漂亮男人2017-05-31 10:40:31

    Just make a pop-up box when asking questions

    reply
    0
  • Cancelreply