From a318de61b6016c4edd341946f29f692d8a7899f1 Mon Sep 17 00:00:00 2001 From: Daniel Herman Date: Sun, 11 Dec 2016 17:19:51 -0500 Subject: [PATCH] fix($rootScope): don't allow explicit digest calls to affect $evalAsync Fixes #15127 --- src/ng/rootScope.js | 2 +- test/ng/rootScopeSpec.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/ng/rootScope.js b/src/ng/rootScope.js index 89279608464c..d4c49e8f9b63 100644 --- a/src/ng/rootScope.js +++ b/src/ng/rootScope.js @@ -764,7 +764,7 @@ function $RootScopeProvider() { var watch, value, last, fn, get, watchers, dirty, ttl = TTL, - next, current, target = this, + next, current, target = asyncQueue.length ? $rootScope : this, watchLog = [], logIdx, asyncTask; diff --git a/test/ng/rootScopeSpec.js b/test/ng/rootScopeSpec.js index 93f3dc9e6eef..26fc5473bdde 100644 --- a/test/ng/rootScopeSpec.js +++ b/test/ng/rootScopeSpec.js @@ -1498,6 +1498,25 @@ describe('Scope', function() { $browser.defer.flush(100000); expect(log).toEqual(['eval-ed 1!', 'eval-ed 2!']); }); + + it('should not have execution affected by an explicit $digest call', function() { + var scope1 = $rootScope.$new(); + var scope2 = $rootScope.$new(); + + scope1.$watch('value', function(value) { + scope1.result = value; + }); + + scope1.$evalAsync(function() { + scope1.value = 'bar'; + }); + + scope2.$digest(); + + $browser.defer.flush(0); + + expect(scope1.result).toBe('bar'); + }); }); });