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

Fix select getting confused when removing options, causing empty option to show up when not needed #10241

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ng/directive/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
self.removeOption = function(value) {
if (this.hasOption(value)) {
delete optionsMap[value];
if (ngModelCtrl.$viewValue == value) {
if (ngModelCtrl.$viewValue === value) {
this.renderUnknownOption(value);
}
}
Expand Down
25 changes: 25 additions & 0 deletions test/ng/directive/selectSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,31 @@ describe('select', function() {
expect(scope.robot).toBe('');
});

it('should not be set when an option is selected and options are set asynchronously',
inject(function($timeout) {
compile('<select ng-model="model" ng-options="opt.id as opt.label for opt in options">' +
'</select>');

scope.$apply(function() {
scope.model = 0;
});

$timeout(function() {
scope.options = [
{id: 0, label: 'x'},
{id: 1, label: 'y'}
];
}, 0);

$timeout.flush();

var options = element.find('option');

expect(options.length).toEqual(2);
expect(options.eq(0)).toEqualOption('0', 'x');
expect(options.eq(1)).toEqualOption('1', 'y');
})
);

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

Expand Down