我有一个问题。我有不同的元素行为。我有一个控制器来处理2个事件:$scope.$on("$destroy", function () { console.log("$destroy"); }); $scope.$on("$locationChangeStart", function () { console.log("$locationChangeStart"); }); 有时候$locationChangeStart事件会先触发,但有时候$destroy事件会先触发。我需要防止页面变化,所以我需要$locationChangeStart先触发。请问,有人知道为什么不同的<a>元素会有不同的事件顺序吗?更新: 我在页面的不同部分使用相同的<a>元素。<a href="#/overview">test</a>
如果您想防止页面更改,无论哪个先启动都没有关系。在您的$locationChangeStart中添加event对象:$scope.$on("$locationChangeStart", function (event) { event.preventDefault(); // will prevent the location change });