diff --git a/src/ng/compile.js b/src/ng/compile.js index bc1cae5bfca6..0887a7086b10 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -3522,7 +3522,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { } recordChanges(scopeName, newValue, oldValue); destination[scopeName] = newValue; - }, deepWatch); + }); removeWatchCollection.push(removeWatch); break; diff --git a/src/ng/parse.js b/src/ng/parse.js index 3e2661e16f6d..fc62eea2839a 100644 --- a/src/ng/parse.js +++ b/src/ng/parse.js @@ -1826,7 +1826,7 @@ function $ParseProvider() { oldInputValueOf = newInputValue && getValueOf(newInputValue); } return lastResult; - }, listener, objectEquality, prettyPrintExpression); + }, listener, objectEquality || parsedExpression.literal, prettyPrintExpression); } var oldInputValueOfValues = []; @@ -1852,7 +1852,7 @@ function $ParseProvider() { } return lastResult; - }, listener, objectEquality, prettyPrintExpression); + }, listener, objectEquality || parsedExpression.literal, prettyPrintExpression); } function oneTimeWatchDelegate(scope, listener, objectEquality, parsedExpression, prettyPrintExpression) { diff --git a/test/ng/parseSpec.js b/test/ng/parseSpec.js index 6af4671b264f..58a3b7a56526 100644 --- a/test/ng/parseSpec.js +++ b/test/ng/parseSpec.js @@ -3117,6 +3117,29 @@ describe('parser', function() { scope.$digest(); expect(objB.value).toBe(scope.input); })); + + it('should support watching literals', inject(function($parse) { + var lastVal = NaN; + var callCount = 0; + var listener = function(val) { callCount++; lastVal = val; }; + + scope.$watch('{val: val}', listener); + + scope.$apply('val = 1'); + expect(callCount).toBe(1); + expect(lastVal).toEqual({val: 1}); + + scope.$apply('val = []'); + expect(callCount).toBe(2); + expect(lastVal).toEqual({val: []}); + + scope.$apply('val = []'); + expect(callCount).toBe(2); + + scope.$apply('val.push(1)'); + expect(callCount).toBe(3); + expect(lastVal).toEqual({val: [1]}); + })); }); describe('locals', function() {