diff --git a/src/ng/rootScope.js b/src/ng/rootScope.js index 89279608464c..16cd5d2b5aeb 100644 --- a/src/ng/rootScope.js +++ b/src/ng/rootScope.js @@ -799,6 +799,10 @@ function $RootScopeProvider() { } asyncQueue.length = 0; + if (this === $rootScope) { + hasRootScopeDigestRun = true; + } + traverseScopesLoop: do { // "traverse the scopes" loop if ((watchers = current.$$watchers)) { @@ -1014,8 +1018,9 @@ function $RootScopeProvider() { // if we are outside of an $digest loop and this is the first time we are scheduling async // task also schedule async auto-flush if (!$rootScope.$$phase && !asyncQueue.length) { + hasRootScopeDigestRun = false; $browser.defer(function() { - if (asyncQueue.length) { + if (!hasRootScopeDigestRun || asyncQueue.length) { $rootScope.$digest(); } }); @@ -1333,6 +1338,7 @@ function $RootScopeProvider() { var postDigestQueue = $rootScope.$$postDigestQueue = []; var applyAsyncQueue = $rootScope.$$applyAsyncQueue = []; + var hasRootScopeDigestRun = false; var postDigestQueuePosition = 0; return $rootScope; diff --git a/test/ng/rootScopeSpec.js b/test/ng/rootScopeSpec.js index 93f3dc9e6eef..55a168701cee 100644 --- a/test/ng/rootScopeSpec.js +++ b/test/ng/rootScopeSpec.js @@ -1498,6 +1498,26 @@ describe('Scope', function() { $browser.defer.flush(100000); expect(log).toEqual(['eval-ed 1!', 'eval-ed 2!']); }); + + + it('should not have execution affected by a local `$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'); + }); }); });