Skip to content

Instantly share code, notes, and snippets.

@mircobabini
Last active November 8, 2018 08:44
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save mircobabini/689955216a036544d594 to your computer and use it in GitHub Desktop.
Save mircobabini/689955216a036544d594 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