Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save voznik/3630756a9aa45e90a840 to your computer and use it in GitHub Desktop.
Save voznik/3630756a9aa45e90a840 to your computer and use it in GitHub Desktop.
HardwareBackButtonManager Service for Ionic (Angular.js) provides an interface to easily enable or disable the hardware back button on Android
.service( 'HardwareBackButtonManager', function($ionicPlatform){
this.deregister = undefined;
this.disable = function(){
this.deregister = $ionicPlatform.registerBackButtonAction(function(e){
e.preventDefault();
return false;
}, 101);
}
this.enable = function(){
if( this.deregister !== undefined ){
this.deregister();
this.deregister = undefined;
}
}
return this;
})
// usage
.controller( 'YourController', function( 'HardwareBackButtonManager' ){
HardwareBackButtonManager.disable();
// re-enable it when you want,
HardwareBackButtonManager.enable();
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment