Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 6b6f12c

Browse files
committed
fix($parse): allow watching object/array literals
1 parent 406c1b0 commit 6b6f12c

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

src/ng/compile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3522,7 +3522,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
35223522
}
35233523
recordChanges(scopeName, newValue, oldValue);
35243524
destination[scopeName] = newValue;
3525-
}, deepWatch);
3525+
});
35263526

35273527
removeWatchCollection.push(removeWatch);
35283528
break;

src/ng/parse.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1826,7 +1826,7 @@ function $ParseProvider() {
18261826
oldInputValueOf = newInputValue && getValueOf(newInputValue);
18271827
}
18281828
return lastResult;
1829-
}, listener, objectEquality, prettyPrintExpression);
1829+
}, listener, objectEquality || parsedExpression.literal, prettyPrintExpression);
18301830
}
18311831

18321832
var oldInputValueOfValues = [];
@@ -1852,7 +1852,7 @@ function $ParseProvider() {
18521852
}
18531853

18541854
return lastResult;
1855-
}, listener, objectEquality, prettyPrintExpression);
1855+
}, listener, objectEquality || parsedExpression.literal, prettyPrintExpression);
18561856
}
18571857

18581858
function oneTimeWatchDelegate(scope, listener, objectEquality, parsedExpression, prettyPrintExpression) {

test/ng/parseSpec.js

+23
Original file line numberDiff line numberDiff line change
@@ -3117,6 +3117,29 @@ describe('parser', function() {
31173117
scope.$digest();
31183118
expect(objB.value).toBe(scope.input);
31193119
}));
3120+
3121+
it('should support watching literals', inject(function($parse) {
3122+
var lastVal = NaN;
3123+
var callCount = 0;
3124+
var listener = function(val) { callCount++; lastVal = val; };
3125+
3126+
scope.$watch('{val: val}', listener);
3127+
3128+
scope.$apply('val = 1');
3129+
expect(callCount).toBe(1);
3130+
expect(lastVal).toEqual({val: 1});
3131+
3132+
scope.$apply('val = []');
3133+
expect(callCount).toBe(2);
3134+
expect(lastVal).toEqual({val: []});
3135+
3136+
scope.$apply('val = []');
3137+
expect(callCount).toBe(2);
3138+
3139+
scope.$apply('val.push(1)');
3140+
expect(callCount).toBe(3);
3141+
expect(lastVal).toEqual({val: [1]});
3142+
}));
31203143
});
31213144

31223145
describe('locals', function() {

0 commit comments

Comments
 (0)