diff --git a/src/ng/parse.js b/src/ng/parse.js index 88d4c9f5f790..1ae26404e610 100644 --- a/src/ng/parse.js +++ b/src/ng/parse.js @@ -1027,11 +1027,7 @@ function $ParseProvider() { cache[exp] = parsedExpression; } - if (parsedExpression.constant) { - parsedExpression.$$unwatch = true; - } - - return oneTime ? oneTimeWrapper(parsedExpression) : parsedExpression; + return oneTime || parsedExpression.constant ? oneTimeWrapper(parsedExpression) : parsedExpression; case 'function': return exp; @@ -1050,7 +1046,7 @@ function $ParseProvider() { function oneTimeParseFn(self, locals) { if (!stable) { - lastValue = expression(self, locals); + lastValue = expression.constant && lastValue ? lastValue : expression(self, locals); oneTimeParseFn.$$unwatch = isDefined(lastValue); if (oneTimeParseFn.$$unwatch && self && self.$$postDigestQueue) { self.$$postDigestQueue.push(function () { diff --git a/test/ng/rootScopeSpec.js b/test/ng/rootScopeSpec.js index 1007e9760f28..adafaed5d8ae 100644 --- a/test/ng/rootScopeSpec.js +++ b/test/ng/rootScopeSpec.js @@ -114,6 +114,15 @@ describe('Scope', function() { expect($rootScope.$$watchers.length).toEqual(0); })); + it('should not keep constant literals on the watch queue', inject(function($rootScope) { + $rootScope.$watch('[]', function() {}); + $rootScope.$watch('{}', function() {}); + expect($rootScope.$$watchers.length).toEqual(2); + $rootScope.$digest(); + + expect($rootScope.$$watchers.length).toEqual(0); + })); + it('should clean up stable watches on the watch queue', inject(function($rootScope, $parse) { $rootScope.$watch($parse('::foo'), function() {}); expect($rootScope.$$watchers.length).toEqual(1);