標籤:$scope 自訂 details dex csdn des current 退出 java
每次點擊返回鍵只會執行一個事件, 在自訂事件中要控制條件不滿足時實行原預設動作. 如果只在一個view中監控, 還需要及時登出事件.
http://www.jianshu.com/p/b567cc657a49
http://blog.csdn.net/liangyiyiliang/article/details/53507411
// 返回鍵, view:100, 條件不滿足再執行預設事件$scope.homebackregister = $ionicPlatform.registerBackButtonAction(function(event) { function showConfirm() { var confirmPopup = $ionicPopup.confirm({ title: ‘<strong>退出應用?</strong>‘, template: ‘你確定要退出嗎?‘, okText: ‘退出‘, cancelText: ‘取消‘ }); confirmPopup.then(function(res) { if (res) { ionic.Platform.exitApp(); } else { $rootScope.backcount = 0; } }); } if ($state.$current.name == ‘home.index‘) { $rootScope.backcount = $rootScope.backcount || 0; $rootScope.backcount++; if ($rootScope.backcount == 2) { showConfirm(); } event.preventDefault(); return false; } else { navigator.app.backHistory(); }}, 101);//只在當前view下註冊, 退出即登出事件$scope.$on(‘$destroy‘, $scope.homebackregister);
ionic android返回鍵