Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Allow change browser URL without reinitialize controller status #1151

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/ng/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,12 @@ LocationUrl.prototype = {
* @private
*/
$$replace: false,

/**
* TODO
* @private
*/
$$preventLocationChangedEvent: false,

/**
* @ngdoc method
Expand Down Expand Up @@ -394,6 +400,16 @@ LocationUrl.prototype = {
replace: function() {
this.$$replace = true;
return this;
},
/**
* TODO
*
* @description
* If called, only browser URL will be updated without reinitialize, for example, controllers
*/
preventLocationChangedEvent: function() {
this.$$preventLocationChangedEvent = true;
return this;
}
};

Expand Down Expand Up @@ -600,7 +616,11 @@ function $LocationProvider(){
} else {
$browser.url($location.absUrl(), $location.$$replace);
$location.$$replace = false;
afterLocationChange(oldUrl);
if (!$location.$$preventLocationChangedEvent) {
afterLocationChange(oldUrl);
} else {
$location.$$preventLocationChangedEvent = false;
}
}
});
}
Expand All @@ -611,6 +631,7 @@ function $LocationProvider(){
return $location;

function afterLocationChange(oldUrl) {
if (!$$onlyChangeUrl
$rootScope.$broadcast('$locationChangeSuccess', $location.absUrl(), oldUrl);
}
}];
Expand Down