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

Commit 9fa73cb

Browse files
committed
fix(select): use strict compare when removing option from ctrl
Otherwise, if the removed option was the empty option (value ''), and the currently selected option had a value of 0, the select would think that the currently selected option had been removed, causing the unknown option to be added again. Fixes #9714 Fixes #10115 Closes #10203
1 parent f645882 commit 9fa73cb

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/ng/directive/select.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
212212
self.removeOption = function(value) {
213213
if (this.hasOption(value)) {
214214
delete optionsMap[value];
215-
if (ngModelCtrl.$viewValue == value) {
215+
if (ngModelCtrl.$viewValue === value) {
216216
this.renderUnknownOption(value);
217217
}
218218
}

test/ng/directive/selectSpec.js

+25
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,31 @@ describe('select', function() {
250250
expect(scope.robot).toBe('');
251251
});
252252

253+
it('should not be set when an option is selected and options are set asynchronously',
254+
inject(function($timeout) {
255+
compile('<select ng-model="model" ng-options="opt.id as opt.label for opt in options">' +
256+
'</select>');
257+
258+
scope.$apply(function() {
259+
scope.model = 0;
260+
});
261+
262+
$timeout(function() {
263+
scope.options = [
264+
{id: 0, label: 'x'},
265+
{id: 1, label: 'y'}
266+
];
267+
}, 0);
268+
269+
$timeout.flush();
270+
271+
var options = element.find('option');
272+
273+
expect(options.length).toEqual(2);
274+
expect(options.eq(0)).toEqualOption('0', 'x');
275+
expect(options.eq(1)).toEqualOption('1', 'y');
276+
})
277+
);
253278

254279
describe('interactions with repeated options', function() {
255280

0 commit comments

Comments
 (0)