Skip to content

Commit

Permalink
fix($location): ensure $locationChangeStart broadcast during $digest
Browse files Browse the repository at this point in the history
I'm not totally convinced this is a necessary change (see comments on angular#5118).

However, feedback valuable. I'll amend this message if it becomes clear that
it's a worthwhile change.
  • Loading branch information
caitp committed Dec 31, 2013
1 parent 1147f21 commit f2d6e32
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions src/ng/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -656,21 +656,30 @@ function $LocationProvider(){
$browser.url($location.absUrl(), true);
}

function browserUrlChange(newUrl) {
if ($rootScope.$broadcast('$locationChangeStart', newUrl,
$location.absUrl()).defaultPrevented) {
$browser.url($location.absUrl());
return;
}
$rootScope.$evalAsync(function() {
var oldUrl = $location.absUrl();

$location.$$parse(newUrl);
afterLocationChange(oldUrl);
});
}

// update $location when $browser url changes
$browser.onUrlChange(function(newUrl) {
if ($location.absUrl() != newUrl) {
if ($rootScope.$broadcast('$locationChangeStart', newUrl,
$location.absUrl()).defaultPrevented) {
$browser.url($location.absUrl());
return;
if ($rootScope.$$phase) {
browserUrlChange(newUrl);
} else {
$rootScope.$apply(function() {
browserUrlChange(newUrl);
});
}
$rootScope.$evalAsync(function() {
var oldUrl = $location.absUrl();

$location.$$parse(newUrl);
afterLocationChange(oldUrl);
});
if (!$rootScope.$$phase) $rootScope.$digest();

This comment has been minimized.

Copy link
@IgorMinar

IgorMinar Jan 3, 2014

shouldn't this line in the original code do the same trick? is the parent if somehow interfering with the expected behavior?

}
});

Expand Down

0 comments on commit f2d6e32

Please sign in to comment.