回到我们刚开始提出的问题,在主页增加按返回键提出退出应用,在其它页面正常返回上个页面,只要注册一个处理事件就可以了,代码如下:
.run(['$ionicPlatform', '$ionicPopup','$rootScope','$location', function ($ionicPlatform, $ionicPopup, $rootScope, $location) {
//主页面显示退出提示框
$ionicPlatform.registerBackButtonAction(function (e) {
e.preventDefault();
function showConfirm() {
var confirmPopup = $ionicPopup.confirm({
title: '<strong>退出应用?</strong>',
template: '你确定要退出应用吗?',
okText: '退出',
cancelText: '取消'
});
confirmPopup.then(function (res) {
if (res) {
ionic.Platform.exitApp();
} else {
// Don't close
}
});
}
// Is there a page to go back to?
if ($location.path() == '/home' ) {
showConfirm();
} else if ($rootScope.$viewHistory.backView ) {
console.log('currentView:', $rootScope.$viewHistory.currentView);
// Go back in history
$rootScope.$viewHistory.backView.go();
} else {
// This is the last page: Show confirmation popup
showConfirm();
}
return false;
}, 101);
}])
网友评论