Skip to content

Commit d2bdf87

Browse files
committed
fix(select): Select option with ngOptions when label equals $viewValue
Fix selectController when using ngOptions and the label equals the $viewValue of the ngModel. Otherwise, when the options are loaded, selectController set the value of the select to a non existing value Fixes angular#11170
1 parent 7d6efe7 commit d2bdf87

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/ng/directive/select.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
222222
self.addOption = function(value, element) {
223223
assertNotHasOwnProperty(value, '"option value"');
224224
optionsMap[value] = true;
225-
225+
226226
if (isUndefined(optionsExp) && ngModelCtrl.$viewValue == value) {
227227
$element.val(value);
228228
if (unknownOption.parent()) unknownOption.remove();

test/ng/directive/selectSpec.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1887,18 +1887,18 @@ describe('select', function() {
18871887
expect(option.val()).toBe('?');
18881888
expect(option.text()).toBe('');
18891889
});
1890-
1891-
it('should select the correct option when label equals $viewValue', function(){
1890+
1891+
it('should select the correct option when label equals $viewValue', function() {
18921892
scope.numbersArray = ["Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten"];
18931893
scope.values= {};
18941894
scope.selected='Four';
18951895
createSelect({
18961896
'ng-model': 'selected',
18971897
'ng-options': 'option.value as option.value for option in values'
18981898
});
1899-
1900-
scope.$apply(function(){
1901-
scope.values=scope.numbersArray.map(function (value, index) {
1899+
1900+
scope.$apply(function() {
1901+
scope.values=scope.numbersArray.map(function(value, index) {
19021902
return {
19031903
id: index,
19041904
value: value
@@ -1909,7 +1909,7 @@ describe('select', function() {
19091909
});
19101910
});
19111911

1912-
1912+
19131913

19141914
describe('blank option', function() {
19151915

0 commit comments

Comments
 (0)