This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +21
-4
lines changed
Expand file tree Collapse file tree 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) {
521521 return {
522522 restrict : 'E' ,
523523 priority : 100 ,
524- require : '^select' ,
525524 compile : function ( element , attr ) {
526525 if ( isUndefined ( attr . value ) ) {
527526 var interpolateFn = $interpolate ( element . text ( ) , true ) ;
@@ -530,8 +529,13 @@ var optionDirective = ['$interpolate', function($interpolate) {
530529 }
531530 }
532531
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 ) {
535539 // For some reason Opera defaults to true and if not overridden this messes up the repeater.
536540 // We don't want the view to drive the initialization of the model anyway.
537541 element . prop ( 'selected' , false ) ;
Original file line number Diff line number Diff line change @@ -1108,7 +1108,7 @@ describe('select', function() {
11081108 } ) ;
11091109
11101110
1111- describe ( 'OPTION value ' , function ( ) {
1111+ describe ( 'option ' , function ( ) {
11121112
11131113 it ( 'should populate value attribute on OPTION' , function ( ) {
11141114 compile ( '<select ng-model="x"><option selected>abc</option></select>' ) ;
@@ -1125,5 +1125,18 @@ describe('select', function() {
11251125 compile ( '<select ng-model="x"><option>hello</select>' ) ;
11261126 expect ( element ) . toEqualSelect ( [ 'hello' ] ) ;
11271127 } ) ;
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+ } ) ) ;
11281141 } ) ;
11291142} ) ;
You can’t perform that action at this time.
0 commit comments