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

Commit aa3c54c

Browse files
baconmaniapetebacondarwin
authored andcommitted
fix(ngOptions): ignore object properties which start with $
1 parent f115751 commit aa3c54c

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/ng/directive/select.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
406406
modelValue = ctrl.$modelValue,
407407
values = valuesFn(scope) || [],
408408
keys = keyName ? sortedKeys(values) : values,
409+
key,
409410
groupLength, length,
410411
groupIndex, index,
411412
locals = {},
@@ -429,8 +430,17 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
429430

430431
// We now build up the list of options we need (we merge later)
431432
for (index = 0; length = keys.length, index < length; index++) {
432-
locals[valueName] = values[keyName ? locals[keyName]=keys[index]:index];
433-
optionGroupName = groupByFn(scope, locals) || '';
433+
434+
key = index;
435+
if (keyName) {
436+
key = keys[index];
437+
if ( key.charAt(0) === '$' ) continue;
438+
locals[keyName] = key;
439+
}
440+
441+
locals[valueName] = values[key];
442+
443+
optionGroupName = groupByFn(scope, locals) || '';
434444
if (!(optionGroup = optionGroups[optionGroupName])) {
435445
optionGroup = optionGroups[optionGroupName] = [];
436446
optionGroupNames.push(optionGroupName);

test/ng/directive/selectSpec.js

+15
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,21 @@ describe('select', function() {
692692
expect(jqLite(element.find('option')[0]).text()).toEqual('blank');
693693
});
694694

695+
it('should ignore $ and $$ properties', function() {
696+
createSelect({
697+
'ng-options': 'key as value for (key, value) in object',
698+
'ng-model': 'selected'
699+
});
700+
701+
scope.$apply(function() {
702+
scope.object = {'regularProperty': 'visible', '$$private': 'invisible', '$property': 'invisible'};
703+
scope.selected = 'regularProperty';
704+
});
705+
706+
var options = element.find('option');
707+
expect(options.length).toEqual(1);
708+
expect(sortedHtml(options[0])).toEqual('<option value="regularProperty">visible</option>');
709+
});
695710

696711
describe('binding', function() {
697712

0 commit comments

Comments
 (0)