Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

They are both undocumented events related to window.location.

like image 789
Lior Avatar asked Feb 21 '13 16:02

Lior


People also ask

What is $locationChangeStart?

$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.

Which is the function of the$ route service?

$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.

What is the purpose of the$ location service in AngularJS?

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.

Which method of $location service is used to get the URL without base prefix?

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.


1 Answers

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

like image 108
pkozlowski.opensource Avatar answered Sep 24 '22 14:09

pkozlowski.opensource