我需要覆盖两个按钮的后退按钮功能:
- 导航栏左上角的后退图标
- 硬件后退按钮(例如在 Android 中)
但仅针对一种特定视图,而不是全局视图。我怎样才能做到这一点?
有可能覆盖两个按钮的后退按钮功能从您的控制器内。这是代码:
// run this function when either hard or soft back button is pressed
var doCustomBack = function() {
console.log("custom BACK");
};
// override soft back
// framework calls $rootScope.$ionicGoBack when soft back button is pressed
var oldSoftBack = $rootScope.$ionicGoBack;
$rootScope.$ionicGoBack = function() {
doCustomBack();
};
var deregisterSoftBack = function() {
$rootScope.$ionicGoBack = oldSoftBack;
};
// override hard back
// registerBackButtonAction() returns a function which can be used to deregister it
var deregisterHardBack = $ionicPlatform.registerBackButtonAction(
doCustomBack, 101
);
// cancel custom back behaviour
$scope.$on('$destroy', function() {
deregisterHardBack();
deregisterSoftBack();
});
确保注入$rootScope
进入控制器。
有关更多详细信息和正确的解释,请参阅我在相关问题上的完整答案:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)