@@ -428,6 +428,9 @@ var ngOptionsDirective = ['$compile', '$document', '$parse', function($compile,
428
428
}
429
429
}
430
430
431
+ // The empty option will be compiled and rendered before we first generate the options
432
+ selectElement . empty ( ) ;
433
+
431
434
var providedEmptyOption = ! ! selectCtrl . emptyOption ;
432
435
433
436
var unknownOption = jqLite ( optionTemplate . cloneNode ( false ) ) ;
@@ -544,13 +547,11 @@ var ngOptionsDirective = ['$compile', '$document', '$parse', function($compile,
544
547
545
548
if ( providedEmptyOption ) {
546
549
547
- // we need to remove it before calling selectElement.empty() because otherwise IE will
548
- // remove the label from the element. wtf?
549
- selectCtrl . emptyOption . remove ( ) ;
550
-
551
550
// compile the element since there might be bindings in it
552
551
$compile ( selectCtrl . emptyOption ) ( scope ) ;
553
552
553
+ selectElement . prepend ( selectCtrl . emptyOption ) ;
554
+
554
555
if ( selectCtrl . emptyOption [ 0 ] . nodeType === NODE_TYPE_COMMENT ) {
555
556
// This means the empty option has currently no actual DOM node, probably because
556
557
// it has been modified by a transclusion directive.
@@ -568,8 +569,12 @@ var ngOptionsDirective = ['$compile', '$document', '$parse', function($compile,
568
569
ngModelCtrl . $render ( ) ;
569
570
570
571
optionEl . on ( '$destroy' , function ( ) {
572
+ var needsRerender = selectCtrl . isEmptyOptionSelected ( ) ;
573
+
571
574
selectCtrl . hasEmptyOption = false ;
572
575
selectCtrl . emptyOption = undefined ;
576
+
577
+ if ( needsRerender ) ngModelCtrl . $render ( ) ;
573
578
} ) ;
574
579
}
575
580
} ;
@@ -582,8 +587,6 @@ var ngOptionsDirective = ['$compile', '$document', '$parse', function($compile,
582
587
583
588
}
584
589
585
- selectElement . empty ( ) ;
586
-
587
590
// We need to do this here to ensure that the options object is defined
588
591
// when we first hit it in writeNgOptionsValue
589
592
updateOptions ( ) ;
@@ -647,16 +650,6 @@ var ngOptionsDirective = ['$compile', '$document', '$parse', function($compile,
647
650
648
651
var groupElementMap = { } ;
649
652
650
- // Ensure that the empty option is always there if it was explicitly provided
651
- if ( providedEmptyOption ) {
652
-
653
- if ( selectCtrl . unknownOption . parent ( ) . length ) {
654
- selectCtrl . unknownOption . after ( selectCtrl . emptyOption ) ;
655
- } else {
656
- selectElement . prepend ( selectCtrl . emptyOption ) ;
657
- }
658
- }
659
-
660
653
options . items . forEach ( function addOption ( option ) {
661
654
var groupElement ;
662
655
0 commit comments