aboutsummaryrefslogtreecommitdiffstats
path: root/src/services.js
diff options
context:
space:
mode:
authorVojta Jina2010-10-31 02:11:50 +0200
committerIgor Minar2010-10-31 21:37:33 -0700
commit99f25050a34a0f0e2b0bdc63a55f38097f7098db (patch)
tree69551702f0ecefb50ab2d399589ba64b501f0dd4 /src/services.js
parentba5f8ee27f03b3215835bc1e643eb25b8f2e217f (diff)
downloadangular.js-99f25050a34a0f0e2b0bdc63a55f38097f7098db.tar.bz2
Fixing issue #98 (infinite loop when location hash set empty)
Added tests and fixed the issue. Closes #98
Diffstat (limited to 'src/services.js')
-rw-r--r--src/services.js21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/services.js b/src/services.js
index 144f6177..fca4bca1 100644
--- a/src/services.js
+++ b/src/services.js
@@ -16,12 +16,15 @@ angularServiceInject("$document", function(window){
angularServiceInject("$location", function(browser) {
var scope = this,
location = {toString:toString, update:update, updateHash: updateHash},
- lastLocationHref = browser.getUrl(),
+ lastBrowserUrl = browser.getUrl(),
+ lastLocationHref,
lastLocationHash;
- browser.addPollFn(function(){
- if (lastLocationHref !== browser.getUrl()) {
- update(lastLocationHref = browser.getUrl());
+ browser.addPollFn(function() {
+ if (lastBrowserUrl != browser.getUrl()) {
+ update(lastBrowserUrl = browser.getUrl());
+ lastLocationHref = location.href;
+ lastLocationHash = location.hash;
scope.$eval();
}
});
@@ -29,7 +32,8 @@ angularServiceInject("$location", function(browser) {
this.$onEval(PRIORITY_FIRST, updateBrowser);
this.$onEval(PRIORITY_LAST, updateBrowser);
- update(lastLocationHref);
+ update(lastBrowserUrl);
+ lastLocationHref = location.href;
lastLocationHash = location.hash;
return location;
@@ -137,8 +141,9 @@ angularServiceInject("$location", function(browser) {
function updateBrowser() {
updateLocation();
- if (location.href != lastLocationHref) {
- browser.setUrl(lastLocationHref = location.href);
+ if (location.href != lastLocationHref) {
+ browser.setUrl(lastBrowserUrl = location.href);
+ lastLocationHref = location.href;
lastLocationHash = location.hash;
}
}
@@ -180,7 +185,7 @@ angularServiceInject("$location", function(browser) {
var match = URL_MATCH.exec(href);
if (match) {
- loc.href = href.replace('#$', '');
+ loc.href = href.replace(/#$/, '');
loc.protocol = match[1];
loc.host = match[3] || '';
loc.port = match[5] || DEFAULT_PORTS[loc.protocol] || _null;