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

Commit

Permalink
fix(ngOptions): ignore object properties which start with $
Browse files Browse the repository at this point in the history
  • Loading branch information
baconmania authored and petebacondarwin committed Sep 13, 2013
1 parent f115751 commit aa3c54c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/ng/directive/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
modelValue = ctrl.$modelValue,
values = valuesFn(scope) || [],
keys = keyName ? sortedKeys(values) : values,
key,
groupLength, length,
groupIndex, index,
locals = {},
Expand All @@ -429,8 +430,17 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {

// We now build up the list of options we need (we merge later)
for (index = 0; length = keys.length, index < length; index++) {
locals[valueName] = values[keyName ? locals[keyName]=keys[index]:index];
optionGroupName = groupByFn(scope, locals) || '';

key = index;
if (keyName) {
key = keys[index];
if ( key.charAt(0) === '$' ) continue;
locals[keyName] = key;
}

locals[valueName] = values[key];

optionGroupName = groupByFn(scope, locals) || '';
if (!(optionGroup = optionGroups[optionGroupName])) {
optionGroup = optionGroups[optionGroupName] = [];
optionGroupNames.push(optionGroupName);
Expand Down
15 changes: 15 additions & 0 deletions test/ng/directive/selectSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,21 @@ describe('select', function() {
expect(jqLite(element.find('option')[0]).text()).toEqual('blank');
});

it('should ignore $ and $$ properties', function() {
createSelect({
'ng-options': 'key as value for (key, value) in object',
'ng-model': 'selected'
});

scope.$apply(function() {
scope.object = {'regularProperty': 'visible', '$$private': 'invisible', '$property': 'invisible'};
scope.selected = 'regularProperty';
});

var options = element.find('option');
expect(options.length).toEqual(1);
expect(sortedHtml(options[0])).toEqual('<option value="regularProperty">visible</option>');
});

describe('binding', function() {

Expand Down

0 comments on commit aa3c54c

Please sign in to comment.