Skip to content

Commit d53330b

Browse files
committed
fix(ngOptions): skip comments when looking for option elements
Closes angular#12190 Closes # 11061
1 parent 0df4ff8 commit d53330b

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/ng/directive/ngOptions.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,10 @@ var ngOptionsDirective = ['$compile', '$parse', function($compile, $parse) {
626626
if (emptyOption_ || unknownOption_) {
627627
while (current &&
628628
(current === emptyOption_ ||
629-
current === unknownOption_)) {
629+
current === unknownOption_ ||
630+
emptyOption_ && emptyOption_.nodeType === NODE_TYPE_COMMENT)) {
631+
// Empty options might have directives that transclude
632+
// and insert comments (e.g. ngIf)
630633
current = current.nextSibling;
631634
}
632635
}

test/ng/directive/ngOptionsSpec.js

+24
Original file line numberDiff line numberDiff line change
@@ -2093,6 +2093,30 @@ describe('ngOptions', function() {
20932093
expect(element[0].selectedIndex).toEqual(0);
20942094
expect(scope.selected).toEqual([]);
20952095
});
2096+
2097+
2098+
it('should be possible to use ngIf in the blank option', function() {
2099+
var option;
2100+
createSingleSelect('<option ng-if="isBlank" value="">blank</option>');
2101+
2102+
scope.$apply(function() {
2103+
scope.values = [{name: 'A'}];
2104+
scope.isBlank = true;
2105+
});
2106+
2107+
expect(element.find('option').length).toBe(2);
2108+
option = element.find('option').eq(0);
2109+
expect(option.val()).toBe('');
2110+
expect(option.text()).toBe('blank');
2111+
2112+
scope.$apply(function() {
2113+
scope.isBlank = false;
2114+
});
2115+
2116+
expect(element.find('option').length).toBe(1);
2117+
option = element.find('option').eq(0);
2118+
expect(option.text()).toBe('A');
2119+
});
20962120
});
20972121

20982122

0 commit comments

Comments
 (0)