diff --git a/src/ng/parse.js b/src/ng/parse.js index ba0ba339c868..98179e8f549b 100644 --- a/src/ng/parse.js +++ b/src/ng/parse.js @@ -717,6 +717,13 @@ function findConstantAndWatchExpressions(ast, $filter) { if (!property.value.constant) { argsToWatch.push.apply(argsToWatch, property.value.toWatch); } + if (property.computed) { + findConstantAndWatchExpressions(property.key, $filter); + if (!property.key.constant) { + argsToWatch.push.apply(argsToWatch, property.key.toWatch); + } + } + }); ast.constant = allConstants; ast.toWatch = argsToWatch; diff --git a/test/ng/parseSpec.js b/test/ng/parseSpec.js index c815bb514261..dbbb2237ad84 100644 --- a/test/ng/parseSpec.js +++ b/test/ng/parseSpec.js @@ -3119,6 +3119,39 @@ describe('parser', function() { expect(objB.value).toBe(scope.input); })); + it('should watch ES6 object computed property changes', function() { + var count = 0; + var values = []; + + scope.$watch('{[a]: true}', function(val) { + count++; + values.push(val); + }, true); + + scope.$digest(); + expect(count).toBe(1); + expect(values[0]).toEqual({'undefined': true}); + + scope.$digest(); + expect(count).toBe(1); + expect(values[0]).toEqual({'undefined': true}); + + scope.a = true; + scope.$digest(); + expect(count).toBe(2); + expect(values[1]).toEqual({'true': true}); + + scope.a = 'abc'; + scope.$digest(); + expect(count).toBe(3); + expect(values[2]).toEqual({'abc': true}); + + scope.a = undefined; + scope.$digest(); + expect(count).toBe(4); + expect(values[3]).toEqual({'undefined': true}); + }); + it('should support watching literals', inject(function($parse) { var lastVal = NaN; var callCount = 0;