diff options
| author | Igor Minar | 2011-10-26 12:15:07 -0700 | 
|---|---|---|
| committer | Igor Minar | 2011-10-26 12:15:07 -0700 | 
| commit | d5ccabce600efb10092fdf0ae033c009026bf4cb (patch) | |
| tree | 3debd4dfe43213252b685ec7fa76459c5337bc9b /src/widgets.js | |
| parent | bb948176aaf6748c0d27772797b4c1490612b917 (diff) | |
| download | angular.js-d5ccabce600efb10092fdf0ae033c009026bf4cb.tar.bz2 | |
fix(ng:view): ignore stale xhr callbacks
A lot of badness happens when we don't ignore stale xhrs. These
raceconditions are only apparent when user clicks through the app very
quckly without waiting for routes to fully load.
Closes #619
Diffstat (limited to 'src/widgets.js')
| -rw-r--r-- | src/widgets.js | 9 | 
1 files changed, 6 insertions, 3 deletions
diff --git a/src/widgets.js b/src/widgets.js index 423fe6dd..c70e9efa 100644 --- a/src/widgets.js +++ b/src/widgets.js @@ -551,13 +551,16 @@ angularWidget('ng:view', function(element) {          changeCounter++;        }); -      this.$watch(function() {return changeCounter;}, function() { +      this.$watch(function() {return changeCounter;}, function(scope, newChangeCounter) {          var template = $route.current && $route.current.template;          if (template) {            //xhr's callback must be async, see commit history for more info            $xhr('GET', template, function(code, response) { -            element.html(response); -            compiler.compile(element)($route.current.scope); +            // ignore callback if another route change occured since +            if (newChangeCounter == changeCounter) { +              element.html(response); +              compiler.compile(element)($route.current.scope); +            }            });          } else {            element.html('');  | 
