mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
Android back button fixes, closes #454
This commit is contained in:
19
js/ext/angular/src/service/ionicView.js
vendored
19
js/ext/angular/src/service/ionicView.js
vendored
@@ -1,8 +1,8 @@
|
||||
angular.module('ionic.service.view', ['ui.router'])
|
||||
|
||||
|
||||
.run( ['$rootScope', '$state', '$location', '$document', '$animate',
|
||||
function( $rootScope, $state, $location, $document, $animate) {
|
||||
.run( ['$rootScope', '$state', '$location', '$document', '$animate', '$ionicPlatform',
|
||||
function( $rootScope, $state, $location, $document, $animate, $ionicPlatform) {
|
||||
|
||||
// init the variables that keep track of the view history
|
||||
$rootScope.$viewHistory = {
|
||||
@@ -49,6 +49,21 @@ angular.module('ionic.service.view', ['ui.router'])
|
||||
}
|
||||
});
|
||||
|
||||
// Triggered when devices with a hardware back button (Android) is clicked by the user
|
||||
// This is a Cordova/Phonegap platform specifc method
|
||||
function onHardwareBackButton(e) {
|
||||
if($rootScope.$viewHistory.backView) {
|
||||
// there is a back view, go to it
|
||||
$rootScope.$viewHistory.backView.go();
|
||||
} else {
|
||||
// there is no back view, so close the app instead
|
||||
navigator.app.exitApp();
|
||||
}
|
||||
e.preventDefault();
|
||||
return false;
|
||||
}
|
||||
$ionicPlatform.onHardwareBackButton(onHardwareBackButton);
|
||||
|
||||
}])
|
||||
|
||||
.factory('$ionicViewService', ['$rootScope', '$state', '$location', '$window', '$injector',
|
||||
|
||||
Reference in New Issue
Block a user