如何处理特定控制器中的浏览器后退按钮事件? [英] How to handle browser back button event in a particular controller?
本文介绍了如何处理特定控制器中的浏览器后退按钮事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想处理特定控制器上的浏览器后退按钮事件(不是每个路由更改,仅针对特定控制器),后退不应更改路由,因为它是ng-include更改
i want to handle the browser back button event on particular controller(not every route change , only for a particular controller), the back should not change the route as it is for an ng-include change
推荐答案
在控制器的 $ scope
中,监听 $ locationChangeStart
事件.在事件处理程序中,通过调用 preventDefault
来确定是否允许更改,以及是否不允许更改位置.
In the $scope
of the controller listen for the $locationChangeStart
event. In the event handler determine if the change is allowed and if not cancel the location change by calling preventDefault
.
$scope.$on('$locationChangeStart', function(event, newUrl, oldUrl) {
if(!allowed /* inject your logic here */) {
event.preventDefault();
}
});
这篇关于如何处理特定控制器中的浏览器后退按钮事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文