Skip to content

Commit

Permalink
fix(ngOptions): skip comments when looking for option elements
Browse files Browse the repository at this point in the history
Closes angular#12190
Closes # 11061
  • Loading branch information
Narretz committed Sep 26, 2015
1 parent 0df4ff8 commit d53330b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/ng/directive/ngOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,10 @@ var ngOptionsDirective = ['$compile', '$parse', function($compile, $parse) {
if (emptyOption_ || unknownOption_) {
while (current &&
(current === emptyOption_ ||
current === unknownOption_)) {
current === unknownOption_ ||
emptyOption_ && emptyOption_.nodeType === NODE_TYPE_COMMENT)) {
// Empty options might have directives that transclude
// and insert comments (e.g. ngIf)
current = current.nextSibling;
}
}
Expand Down
24 changes: 24 additions & 0 deletions test/ng/directive/ngOptionsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2093,6 +2093,30 @@ describe('ngOptions', function() {
expect(element[0].selectedIndex).toEqual(0);
expect(scope.selected).toEqual([]);
});


it('should be possible to use ngIf in the blank option', function() {
var option;
createSingleSelect('<option ng-if="isBlank" value="">blank</option>');

scope.$apply(function() {
scope.values = [{name: 'A'}];
scope.isBlank = true;
});

expect(element.find('option').length).toBe(2);
option = element.find('option').eq(0);
expect(option.val()).toBe('');
expect(option.text()).toBe('blank');

scope.$apply(function() {
scope.isBlank = false;
});

expect(element.find('option').length).toBe(1);
option = element.find('option').eq(0);
expect(option.text()).toBe('A');
});
});


Expand Down

0 comments on commit d53330b

Please sign in to comment.