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

Commit 1bd55d9

Browse files
committed
remove cruft, remove selected from empty option
1 parent caac012 commit 1bd55d9

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/ng/directive/ngOptions.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ var ngOptionsDirective = ['$compile', '$document', '$parse', function($compile,
475475
if (selectedOption) selectedOption.element.removeAttribute('selected');
476476

477477
if (option) {
478+
if (providedEmptyOption) emptyOption.removeAttr('selected');
478479
// Don't update the option when it is already selected.
479480
// For example, the browser will select the first option by default. In that case,
480481
// most properties are set automatically - except the `selected` attribute, which we

test/ng/directive/ngOptionsSpec.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,7 @@ describe('ngOptions', function() {
743743
expect(options.eq(3)).toEqualOption('c');
744744
});
745745

746+
746747
it('should remove the "selected" attribute from the previous option when the model changes', function() {
747748
scope.values = [{id: 10, label: 'ten'}, {id:20, label: 'twenty'}];
748749

@@ -751,18 +752,22 @@ describe('ngOptions', function() {
751752
'ng-options': 'item.label for item in values'
752753
}, true);
753754

754-
var resetButton = angular.element('<input type="reset" />');
755-
formElement.append(resetButton);
755+
var options = element.find('option');
756+
expect(options[0].getAttribute('selected')).toBe('selected');
757+
expect(options[1].hasAttribute('selected')).toBe(false);
758+
expect(options[2].hasAttribute('selected')).toBe(false);
756759

757760
scope.selected = scope.values[0];
758761
scope.$digest();
759762

760-
var options = element.find('option');
763+
expect(options[0].hasAttribute('selected')).toBe(false);
761764
expect(options[1].getAttribute('selected')).toBe('selected');
765+
expect(options[2].hasAttribute('selected')).toBe(false);
762766

763767
scope.selected = scope.values[1];
764768
scope.$digest();
765769

770+
expect(options[0].hasAttribute('selected')).toBe(false);
766771
expect(options[1].hasAttribute('selected')).toBe(false);
767772
expect(options[2].getAttribute('selected')).toBe('selected');
768773

@@ -1441,7 +1446,6 @@ describe('ngOptions', function() {
14411446
scope.selected = {};
14421447
scope.$digest();
14431448

1444-
options[2].selected = false;
14451449
expect(options[0].selected).toBe(true);
14461450
expect(options[0].getAttribute('selected')).toBe('selected');
14471451
expect(options[2].selected).toBe(false);

0 commit comments

Comments
 (0)