diff options
| -rw-r--r-- | src/ng/rootScope.js | 7 | ||||
| -rw-r--r-- | test/ng/rootScopeSpec.js | 16 |
2 files changed, 19 insertions, 4 deletions
diff --git a/src/ng/rootScope.js b/src/ng/rootScope.js index 8f9be5e6..32142b38 100644 --- a/src/ng/rootScope.js +++ b/src/ng/rootScope.js @@ -501,7 +501,7 @@ function $RootScopeProvider(){ dirty, ttl = TTL, next, current, target = this, watchLog = [], - logIdx, logMsg; + logIdx, logMsg, asyncTask; beginPhase('$digest'); @@ -511,7 +511,8 @@ function $RootScopeProvider(){ while(asyncQueue.length) { try { - current.$eval(asyncQueue.shift()); + asyncTask = asyncQueue.shift(); + asyncTask.scope.$eval(asyncTask.expression); } catch (e) { $exceptionHandler(e); } @@ -704,7 +705,7 @@ function $RootScopeProvider(){ }); } - this.$$asyncQueue.push(expr); + this.$$asyncQueue.push({scope: this, expression: expr}); }, $$postDigest : function(fn) { diff --git a/test/ng/rootScopeSpec.js b/test/ng/rootScopeSpec.js index a23db81a..e8bf8eed 100644 --- a/test/ng/rootScopeSpec.js +++ b/test/ng/rootScopeSpec.js @@ -766,6 +766,17 @@ describe('Scope', function() { expect($rootScope.log).toBe('12'); })); + it('should run async expressions in their proper context', inject(function ($rootScope) { + var child = $rootScope.$new(); + $rootScope.ctx = 'root context'; + $rootScope.log = ''; + child.ctx = 'child context'; + child.log = ''; + child.$evalAsync('log=ctx'); + $rootScope.$digest(); + expect($rootScope.log).toBe(''); + expect(child.log).toBe('child context'); + })); it('should operate only with a single queue across all child and isolate scopes', inject(function($rootScope) { var childScope = $rootScope.$new(); @@ -777,7 +788,10 @@ describe('Scope', function() { expect(childScope.$$asyncQueue).toBe($rootScope.$$asyncQueue); expect(isolateScope.$$asyncQueue).toBe($rootScope.$$asyncQueue); - expect($rootScope.$$asyncQueue).toEqual(['rootExpression', 'childExpression', 'isolateExpression']); + expect($rootScope.$$asyncQueue).toEqual([ + {scope: $rootScope, expression: 'rootExpression'}, + {scope: childScope, expression: 'childExpression'}, + {scope: isolateScope, expression: 'isolateExpression'}]); })); |
