diff --git a/src/ng/parse.js b/src/ng/parse.js index 8d4fc5106c11..3a08d8b900a1 100644 --- a/src/ng/parse.js +++ b/src/ng/parse.js @@ -815,6 +815,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 3bf4521b3645..1df4a3135690 100644 --- a/test/ng/parseSpec.js +++ b/test/ng/parseSpec.js @@ -3868,6 +3868,40 @@ describe('parser', function() { scope.$digest(); 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}); + }); + }); describe('locals', function() {