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?
某草草
某草草 2017-05-31 10:38:31
0
1
634

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.

某草草
某草草

reply all(1)
漂亮男人

Just make a pop-up box when asking questions

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!