This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +21
-4
lines changed
2 files changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -521,7 +521,6 @@ var optionDirective = ['$interpolate', function($interpolate) {
521
521
return {
522
522
restrict : 'E' ,
523
523
priority : 100 ,
524
- require : '^select' ,
525
524
compile : function ( element , attr ) {
526
525
if ( isUndefined ( attr . value ) ) {
527
526
var interpolateFn = $interpolate ( element . text ( ) , true ) ;
@@ -530,8 +529,13 @@ var optionDirective = ['$interpolate', function($interpolate) {
530
529
}
531
530
}
532
531
533
- return function ( scope , element , attr , selectCtrl ) {
534
- if ( selectCtrl . databound ) {
532
+ return function ( scope , element , attr ) {
533
+ var selectCtrlName = '$selectController' ,
534
+ parent = element . parent ( ) ,
535
+ selectCtrl = parent . data ( selectCtrlName ) ||
536
+ parent . parent ( ) . data ( selectCtrlName ) ; // in case we are in optgroup
537
+
538
+ if ( selectCtrl && selectCtrl . databound ) {
535
539
// For some reason Opera defaults to true and if not overridden this messes up the repeater.
536
540
// We don't want the view to drive the initialization of the model anyway.
537
541
element . prop ( 'selected' , false ) ;
Original file line number Diff line number Diff line change @@ -1108,7 +1108,7 @@ describe('select', function() {
1108
1108
} ) ;
1109
1109
1110
1110
1111
- describe ( 'OPTION value ' , function ( ) {
1111
+ describe ( 'option ' , function ( ) {
1112
1112
1113
1113
it ( 'should populate value attribute on OPTION' , function ( ) {
1114
1114
compile ( '<select ng-model="x"><option selected>abc</option></select>' ) ;
@@ -1125,5 +1125,18 @@ describe('select', function() {
1125
1125
compile ( '<select ng-model="x"><option>hello</select>' ) ;
1126
1126
expect ( element ) . toEqualSelect ( [ 'hello' ] ) ;
1127
1127
} ) ;
1128
+
1129
+ it ( 'should not blow up when option directive is found inside of a datalist' ,
1130
+ inject ( function ( $compile , $rootScope ) {
1131
+ var element = $compile ( '<div>' +
1132
+ '<datalist><option>some val</option></datalist>' +
1133
+ '<span>{{foo}}</span>' +
1134
+ '</div>' ) ( $rootScope ) ;
1135
+
1136
+ $rootScope . foo = 'success' ;
1137
+ $rootScope . $digest ( ) ;
1138
+ expect ( element . find ( 'span' ) . text ( ) ) . toBe ( 'success' ) ;
1139
+ dealoc ( element ) ;
1140
+ } ) ) ;
1128
1141
} ) ;
1129
1142
} ) ;
You can’t perform that action at this time.
0 commit comments