@@ -399,16 +399,22 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
399
399
optionGroup = optionGroupsCache [ groupIndex ] ;
400
400
401
401
for ( index = 1 , length = optionGroup . length ; index < length ; index ++ ) {
402
- //Have to use attr because element[0].selected returns false when multiple selected
403
- if ( ( optionElement = optionGroup [ index ] . element ) . attr ( 'selected' ) ) {
402
+ if ( ( optionElement = optionGroup [ index ] . element ) [ 0 ] . selected ) {
404
403
key = optionElement . val ( ) ;
405
404
if ( keyName ) locals [ keyName ] = key ;
406
405
if ( selectAsFn ) {
407
406
var collectionWithValueName = { } ;
408
407
collectionWithValueName [ valueName ] = collection [ key ] ;
409
- for ( i = 0 ; i < collection . length ; i ++ ) {
410
- locals [ valueName ] = collection [ i ] ;
411
- if ( selectAsFn ( scope , locals ) == selectAsFn ( scope , collectionWithValueName ) ) break ;
408
+ collectionWithValueName [ keyName ] = key ;
409
+
410
+ for ( i in collection ) {
411
+ if ( collection . hasOwnProperty ( i ) ) {
412
+ locals [ valueName ] = collection [ i ] ;
413
+ locals [ keyName ] = i ;
414
+ if ( selectAsFn ( scope , locals ) ==
415
+ selectAsFn ( scope , collectionWithValueName ) ) break ;
416
+ }
417
+
412
418
}
413
419
} else if ( trackFn ) {
414
420
for ( trackIndex = 0 ; trackIndex < collection . length ; trackIndex ++ ) {
@@ -418,7 +424,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
418
424
} else {
419
425
locals [ valueName ] = collection [ key ] ;
420
426
}
421
- value . push ( valueFn ( scope , locals ) ) ;
427
+ value . push ( ( selectAsFn || valueFn ) ( scope , locals ) ) ;
422
428
}
423
429
}
424
430
}
0 commit comments