Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e3ad9f5

Browse files
committedSep 25, 2015
fix(ngOptions): skip comments when looking for option elements
Closes angular#12190
1 parent 0df4ff8 commit e3ad9f5

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-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_.nodeType === Node.COMMENT_NODE)) {
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

+25
Original file line numberDiff line numberDiff line change
@@ -2093,6 +2093,31 @@ 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+
});
2120+
20962121
});
20972122

20982123

0 commit comments

Comments
 (0)
Please sign in to comment.