Skip to content

Commit 7aa4f95

Browse files
committed
fix(ngOptions): ignore array properties beginning with $$
Fixes angular#11930
1 parent 291d7c4 commit 7aa4f95

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/ng/directive/ngOptions.js

+13
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,13 @@ var ngOptionsDirective = ['$compile', '$parse', function($compile, $parse) {
303303
values = values || [];
304304

305305
Object.keys(values).forEach(function getWatchable(key) {
306+
if (isString(values[key]) &&
307+
values[key].charAt(0) == '$' &&
308+
values[key].charAt(1) == '$'
309+
) {
310+
return;
311+
}
312+
306313
var locals = getLocals(values[key], key);
307314
var selectValue = getTrackByValueFn(values[key], locals);
308315
watchedArray.push(selectValue);
@@ -348,6 +355,12 @@ var ngOptionsDirective = ['$compile', '$parse', function($compile, $parse) {
348355
var optionValuesLength = optionValuesKeys.length;
349356

350357
for (var index = 0; index < optionValuesLength; index++) {
358+
if (isString(optionValuesKeys[index]) &&
359+
optionValuesKeys[index].charAt(0) === '$' &&
360+
optionValuesKeys[index].charAt(1) === '$'
361+
) {
362+
continue;
363+
}
351364
var key = (optionValues === optionValuesKeys) ? index : optionValuesKeys[index];
352365
var value = optionValues[key];
353366
var locals = getLocals(value, key);

test/ng/directive/ngOptionsSpec.js

+19
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,25 @@ describe('ngOptions', function() {
922922
expect(scope.selected).toEqual([20]);
923923
expect(element).toEqualSelectValue([20], true);
924924
});
925+
926+
927+
it('should ignore array values beginning with $$', function() {
928+
scope.arr = ['one', 'two', '$$hashKey'];
929+
930+
scope.modify = function(item) {
931+
return item;
932+
};
933+
934+
spyOn(scope, 'modify');
935+
936+
createSelect({
937+
'ng-model': 'selected',
938+
'multiple': false,
939+
'ng-options': 'item as modify(item) for item in arr'
940+
});
941+
942+
expect(scope.modify).not.toHaveBeenCalledWith('$$hashKey');
943+
});
925944
});
926945

927946

0 commit comments

Comments
 (0)