From b232274f2b6f791fbc7e62607aa305e79ebafc83 Mon Sep 17 00:00:00 2001 From: andresmoschini Date: Wed, 18 Jul 2012 09:13:11 -0300 Subject: [PATCH 1/2] Update $location in order to allow change browser URL without reinitialize controller status --- src/ng/location.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/ng/location.js b/src/ng/location.js index cf50952d53c3..264d1519ea10 100644 --- a/src/ng/location.js +++ b/src/ng/location.js @@ -222,6 +222,12 @@ LocationUrl.prototype = { * @private */ $$replace: false, + + /** + * TODO + * @private + */ + $$preventLocationChangedEvent: false, /** * @ngdoc method @@ -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; } }; @@ -600,7 +616,9 @@ function $LocationProvider(){ } else { $browser.url($location.absUrl(), $location.$$replace); $location.$$replace = false; - afterLocationChange(oldUrl); + if (!$location.$$preventLocationChangedEvent) { + afterLocationChange(oldUrl); + } } }); } @@ -611,6 +629,7 @@ function $LocationProvider(){ return $location; function afterLocationChange(oldUrl) { + if (!$$onlyChangeUrl $rootScope.$broadcast('$locationChangeSuccess', $location.absUrl(), oldUrl); } }]; From 5c5fecbeee0a9ceca673174d71833e1e47507f78 Mon Sep 17 00:00:00 2001 From: andresmoschini Date: Wed, 29 Aug 2012 10:05:19 -0300 Subject: [PATCH 2/2] Reset preventLocationChanged state after use it --- src/ng/location.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ng/location.js b/src/ng/location.js index 264d1519ea10..6a2dacec4f1e 100644 --- a/src/ng/location.js +++ b/src/ng/location.js @@ -618,6 +618,8 @@ function $LocationProvider(){ $location.$$replace = false; if (!$location.$$preventLocationChangedEvent) { afterLocationChange(oldUrl); + } else { + $location.$$preventLocationChangedEvent = false; } } });