diff --git a/src/ng/directive/select.js b/src/ng/directive/select.js
index b957fa623b31..df2359d12294 100644
--- a/src/ng/directive/select.js
+++ b/src/ng/directive/select.js
@@ -623,6 +623,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
updateLabelMap(labelMap, existingOption.label, false);
updateLabelMap(labelMap, option.label, true);
lastElement.text(existingOption.label = option.label);
+ lastElement.prop('label', existingOption.label);
}
if (existingOption.id !== option.id) {
lastElement.val(existingOption.id = option.id);
@@ -652,6 +653,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
.val(option.id)
.prop('selected', option.selected)
.attr('selected', option.selected)
+ .prop('label', option.label)
.text(option.label);
}
diff --git a/test/ng/directive/selectSpec.js b/test/ng/directive/selectSpec.js
index 7fb1121f4720..4abde899325a 100644
--- a/test/ng/directive/selectSpec.js
+++ b/test/ng/directive/selectSpec.js
@@ -38,8 +38,28 @@ describe('select', function() {
};
return equals(expectedValues, actualValues);
+ },
+
+ toEqualOption: function(value, text, label) {
+ var errors = [];
+ if (this.actual.attr('value') !== value) {
+ errors.push('Expected option value "' + this.actual.attr('value') + '" to equal "' + value + '"');
+ }
+ if (text && this.actual.text() !== text) {
+ errors.push('Expected option value "' + this.actual.attr('value') + '" to equal "' + value + '"');
+ }
+ if (label && this.actual.attr('label') !== label) {
+ errors.push('Expected option value "' + this.actual.attr('value') + '" to equal "' + value + '"');
+ }
+
+ this.message = function() {
+ return errors.join('\n');
+ };
+
+ return errors.length === 0;
}
});
+
});
@@ -756,9 +776,9 @@ describe('select', function() {
var options = element.find('option');
expect(options.length).toEqual(3);
- expect(sortedHtml(options[0])).toEqual('');
- expect(sortedHtml(options[1])).toEqual('');
- expect(sortedHtml(options[2])).toEqual('');
+ expect(options.eq(0)).toEqualOption('?', '');
+ expect(options.eq(1)).toEqualOption('10', 'ten');
+ expect(options.eq(2)).toEqualOption('20', 'twenty');
});
it('should preserve value even when reference has changed (single&array)', function() {
@@ -1047,9 +1067,9 @@ describe('select', function() {
var options = element.find('option');
expect(options.length).toEqual(3);
- expect(sortedHtml(options[0])).toEqual('');
- expect(sortedHtml(options[1])).toEqual('');
- expect(sortedHtml(options[2])).toEqual('');
+ expect(options.eq(0)).toEqualOption('0', 'A');
+ expect(options.eq(1)).toEqualOption('1', 'B');
+ expect(options.eq(2)).toEqualOption('2', 'C');
});
it('should render zero as a valid display value', function() {
@@ -1062,9 +1082,9 @@ describe('select', function() {
var options = element.find('option');
expect(options.length).toEqual(3);
- expect(sortedHtml(options[0])).toEqual('');
- expect(sortedHtml(options[1])).toEqual('');
- expect(sortedHtml(options[2])).toEqual('');
+ expect(options.eq(0)).toEqualOption('0', '0');
+ expect(options.eq(1)).toEqualOption('1', '1');
+ expect(options.eq(2)).toEqualOption('2', '2');
});
@@ -1081,9 +1101,9 @@ describe('select', function() {
var options = element.find('option');
expect(options.length).toEqual(3);
- expect(sortedHtml(options[0])).toEqual('');
- expect(sortedHtml(options[1])).toEqual('');
- expect(sortedHtml(options[2])).toEqual('');
+ expect(options.eq(0)).toEqualOption('blue', 'blue');
+ expect(options.eq(1)).toEqualOption('green', 'green');
+ expect(options.eq(2)).toEqualOption('red', 'red');
expect(options[2].selected).toEqual(true);
scope.$apply(function() {
@@ -1103,7 +1123,7 @@ describe('select', function() {
});
expect(element.find('option').length).toEqual(1); // because we add special empty option
- expect(sortedHtml(element.find('option')[0])).toEqual('');
+ expect(element.find('option')).toEqualOption('?','');
scope.$apply(function() {
scope.values.push({name:'A'});
@@ -1111,15 +1131,15 @@ describe('select', function() {
});
expect(element.find('option').length).toEqual(1);
- expect(sortedHtml(element.find('option')[0])).toEqual('');
+ expect(element.find('option')).toEqualOption('0', 'A');
scope.$apply(function() {
scope.values.push({name:'B'});
});
expect(element.find('option').length).toEqual(2);
- expect(sortedHtml(element.find('option')[0])).toEqual('');
- expect(sortedHtml(element.find('option')[1])).toEqual('');
+ expect(element.find('option').eq(0)).toEqualOption('0', 'A');
+ expect(element.find('option').eq(1)).toEqualOption('1', 'B');
});
@@ -1138,15 +1158,15 @@ describe('select', function() {
});
expect(element.find('option').length).toEqual(2);
- expect(sortedHtml(element.find('option')[0])).toEqual('');
- expect(sortedHtml(element.find('option')[1])).toEqual('');
+ expect(element.find('option').eq(0)).toEqualOption('0', 'A');
+ expect(element.find('option').eq(1)).toEqualOption('1', 'B');
scope.$apply(function() {
scope.values.pop();
});
expect(element.find('option').length).toEqual(1);
- expect(sortedHtml(element.find('option')[0])).toEqual('');
+ expect(element.find('option')).toEqualOption('0', 'A');
scope.$apply(function() {
scope.values.pop();
@@ -1198,9 +1218,9 @@ describe('select', function() {
var options = element.find('option');
expect(options.length).toEqual(3);
- expect(sortedHtml(options[0])).toEqual('');
- expect(sortedHtml(options[1])).toEqual('');
- expect(sortedHtml(options[2])).toEqual('');
+ expect(options.eq(0)).toEqualOption('0', 'B');
+ expect(options.eq(1)).toEqualOption('1', 'C');
+ expect(options.eq(2)).toEqualOption('2', 'D');
});
@@ -1244,7 +1264,7 @@ describe('select', function() {
var options = element.find('option');
expect(options.length).toEqual(1);
- expect(sortedHtml(options[0])).toEqual('');
+ expect(options.eq(0)).toEqualOption('regularProperty', 'visible');
});
it('should allow expressions over multiple lines', function() {
@@ -1268,8 +1288,8 @@ describe('select', function() {
var options = element.find('option');
expect(options.length).toEqual(3);
- expect(sortedHtml(options[1])).toEqual('');
- expect(sortedHtml(options[2])).toEqual('');
+ expect(options.eq(1)).toEqualOption('0', '2');
+ expect(options.eq(2)).toEqualOption('1', '3');
});
it('should not update selected property of an option element on digest with no change event',
@@ -1300,6 +1320,23 @@ describe('select', function() {
expect(scope.selected).toBe(scope.values[0]);
});
+ // bug fix #9621
+ it('should update the label property', function() {
+ // ng-options="value.name for value in values"
+ // ng-model="selected"
+ createSingleSelect();
+
+ scope.$apply(function() {
+ scope.values = [{name: 'A'}, {name: 'B'}, {name: 'C'}];
+ scope.selected = scope.values[0];
+ });
+
+ var options = element.find('option');
+ expect(options.eq(0).prop('label')).toEqual('A');
+ expect(options.eq(1).prop('label')).toEqual('B');
+ expect(options.eq(2).prop('label')).toEqual('C');
+ });
+
describe('binding', function() {
it('should bind to scope value', function() {
@@ -1426,8 +1463,8 @@ describe('select', function() {
var options = element.find('option');
expect(options.length).toEqual(2);
- expect(sortedHtml(options[0])).toEqual('');
- expect(sortedHtml(options[1])).toEqual('');
+ expect(options.eq(0)).toEqualOption('0', 'C');
+ expect(options.eq(1)).toEqualOption('1', 'B');
});
@@ -1447,8 +1484,8 @@ describe('select', function() {
var options = element.find('option');
expect(options.length).toEqual(2);
- expect(sortedHtml(options[0])).toEqual('');
- expect(sortedHtml(options[1])).toEqual('');
+ expect(options.eq(0)).toEqualOption('a', 'C');
+ expect(options.eq(1)).toEqualOption('b', 'B');
});