diff options
| author | Gowtam Lal | 2013-09-13 12:41:51 +0100 |
|---|---|---|
| committer | Pete Bacon Darwin | 2013-09-13 13:22:36 +0100 |
| commit | 9ef5d8f31827ba5757ff03fe32fed6757517a36c (patch) | |
| tree | 32b50a6f4fc7e2f6eec45931de1ffafca1386d0c | |
| parent | 6a634e309b0fbfc2e20ada946de9979be2b405af (diff) | |
| download | angular.js-9ef5d8f31827ba5757ff03fe32fed6757517a36c.tar.bz2 | |
fix(ngOptions): ignore object properties which start with $
| -rw-r--r-- | src/ng/directive/select.js | 14 | ||||
| -rw-r--r-- | test/ng/directive/selectSpec.js | 15 |
2 files changed, 27 insertions, 2 deletions
diff --git a/src/ng/directive/select.js b/src/ng/directive/select.js index 36620dca..71742191 100644 --- a/src/ng/directive/select.js +++ b/src/ng/directive/select.js @@ -384,6 +384,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 = {}, @@ -399,8 +400,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); diff --git a/test/ng/directive/selectSpec.js b/test/ng/directive/selectSpec.js index 91d09893..c498b095 100644 --- a/test/ng/directive/selectSpec.js +++ b/test/ng/directive/selectSpec.js @@ -693,6 +693,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() { |
