问题描述
$locationChangeSuccess
和 $locationChangeStart
有什么区别?
它们都是与 window.location
相关的未记录事件.
They are both undocumented events related to window.location
.
推荐答案
$locationChangeStart
在 AngularJS 开始根据通过 $location
完成的更改更新浏览器位置时触发服务($location.path()
, $location.search()
).
The $locationChangeStart
is fired when AngularJS starts to update browser's location based on mutations done via $location
service ($location.path()
, $location.search()
).
应用程序可能会侦听 $locationChangeStart
事件并对其调用 preventDefault()
.在这种情况下,第二个事件 ($locationChangeSuccess
) 将不会广播.
It might happen that an application will listen to the $locationChangeStart
event and will call preventDefault()
on it. In this case the second event ($locationChangeSuccess
) won't be broadcasting.
简而言之:$locationChangeStart
在位置更新时触发.如果没有阻止第一个操作,则后面跟着 $locationChangeSuccess
.
In short: $locationChangeStart
fires when the location gets updated. It is followed by $locationChangeSuccess
if the first action wasn't prevented.
源代码的相关部分在这里:https://github.com/angular/angular.js/blob/2508b47c1a34dfc834f8fde858574f81af4d287e/src/ng/location.js#L598
Relevant bits of the source code are here:https://github.com/angular/angular.js/blob/2508b47c1a34dfc834f8fde858574f81af4d287e/src/ng/location.js#L598
这篇关于$locationChangeSuccess 和 $locationChangeStart 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!