What's the difference between $locationChangeSuccess
and $locationChangeStart
?
They are both undocumented events related to window.location
.
$locationChangeStart: this uses the $location provider and broadcasts whenever the URL changes. Location refers more to a Path of a specific URL. It's more like plain JavaScript, you can change to any path in your application and it doesn't matter if it's defined on your app as route or state.
$route is used for deep-linking URLs to controllers and views (HTML partials). It watches $location. url() and tries to map the path to an existing route definition.
The $location service parses the URL in the browser address bar (based on the window. location) and makes the URL available to your application. Changes to the URL in the address bar are reflected into $location service and changes to $location are reflected into the browser address bar.
hash() Method: It is a read and writes method of $location service. It returns the current hash value of the current URL when called without parameters and when called with parameters it returns the$location object.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With