What's the difference between $locationChangeSuccess and $locationChangeStart?

喜你入骨 提交于 2019-11-28 21:45:41

问题


What's the difference between $locationChangeSuccess and $locationChangeStart?

They are both undocumented events related to window.location.


回答1:


The $locationChangeStart is fired when AngularJS starts to update browser's location based on mutations done via $location service ($location.path(), $location.search()).

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.

In short: $locationChangeStart fires when the location gets updated. It is followed by $locationChangeSuccess if the first action wasn't prevented.

Relevant bits of the source code are here: https://github.com/angular/angular.js/blob/2508b47c1a34dfc834f8fde858574f81af4d287e/src/ng/location.js#L598



来源:https://stackoverflow.com/questions/15006849/whats-the-difference-between-locationchangesuccess-and-locationchangestart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!