@@ -66,7 +66,9 @@ uis.controller('uiSelectCtrl',
66
66
ctrl . search = EMPTY_SEARCH ;
67
67
//reset activeIndex
68
68
if ( ctrl . selected && ctrl . items . length && ! ctrl . multiple ) {
69
- ctrl . activeIndex = ctrl . items . indexOf ( ctrl . selected ) ;
69
+ ctrl . activeIndex = ctrl . items . findIndex ( function ( item ) {
70
+ return angular . equals ( this , item ) ;
71
+ } , ctrl . selected ) ;
70
72
}
71
73
}
72
74
}
@@ -259,7 +261,7 @@ uis.controller('uiSelectCtrl',
259
261
return false ;
260
262
}
261
263
var itemIndex = ctrl . items . indexOf ( itemScope [ ctrl . itemProperty ] ) ;
262
- var isActive = itemIndex === ctrl . activeIndex ;
264
+ var isActive = itemIndex == ctrl . activeIndex ;
263
265
264
266
if ( ! isActive || ( itemIndex < 0 && ctrl . taggingLabel !== false ) || ( itemIndex < 0 && ctrl . taggingLabel === false ) ) {
265
267
return false ;
@@ -573,3 +575,27 @@ uis.controller('uiSelectCtrl',
573
575
} ) ;
574
576
575
577
} ] ) ;
578
+
579
+ // Array findIndex polyfill (source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex#Polyfill)
580
+ if ( ! Array . prototype . findIndex ) {
581
+ Array . prototype . findIndex = function ( predicate ) {
582
+ if ( this === null ) {
583
+ throw new TypeError ( 'Array.prototype.findIndex called on null or undefined' ) ;
584
+ }
585
+ if ( typeof predicate !== 'function' ) {
586
+ throw new TypeError ( 'predicate must be a function' ) ;
587
+ }
588
+ var list = Object ( this ) ;
589
+ var length = list . length >>> 0 ;
590
+ var thisArg = arguments [ 1 ] ;
591
+ var value ;
592
+
593
+ for ( var i = 0 ; i < length ; i ++ ) {
594
+ value = list [ i ] ;
595
+ if ( predicate . call ( thisArg , value , i , list ) ) {
596
+ return i ;
597
+ }
598
+ }
599
+ return - 1 ;
600
+ } ;
601
+ }
0 commit comments