mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-19 20:01:52 +00:00
fix(ngOptions): ignore object properties which start with $
This commit is contained in:
parent
6a634e309b
commit
9ef5d8f318
2 changed files with 27 additions and 2 deletions
|
|
@ -384,6 +384,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
|
||||||
modelValue = ctrl.$modelValue,
|
modelValue = ctrl.$modelValue,
|
||||||
values = valuesFn(scope) || [],
|
values = valuesFn(scope) || [],
|
||||||
keys = keyName ? sortedKeys(values) : values,
|
keys = keyName ? sortedKeys(values) : values,
|
||||||
|
key,
|
||||||
groupLength, length,
|
groupLength, length,
|
||||||
groupIndex, index,
|
groupIndex, index,
|
||||||
locals = {},
|
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)
|
// We now build up the list of options we need (we merge later)
|
||||||
for (index = 0; length = keys.length, index < length; index++) {
|
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])) {
|
if (!(optionGroup = optionGroups[optionGroupName])) {
|
||||||
optionGroup = optionGroups[optionGroupName] = [];
|
optionGroup = optionGroups[optionGroupName] = [];
|
||||||
optionGroupNames.push(optionGroupName);
|
optionGroupNames.push(optionGroupName);
|
||||||
|
|
|
||||||
|
|
@ -693,6 +693,21 @@ describe('select', function() {
|
||||||
expect(jqLite(element.find('option')[0]).text()).toEqual('blank');
|
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() {
|
describe('binding', function() {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue