@@ -292,20 +292,41 @@ var ngOptionsDirective = ['$compile', '$parse', function($compile, $parse) {
292
292
this . disabled = disabled ;
293
293
}
294
294
295
+ function getOptionValuesKeys ( optionValues ) {
296
+ var optionValuesKeys ;
297
+
298
+ if ( ! keyName && isArrayLike ( optionValues ) ) {
299
+ optionValuesKeys = optionValues ;
300
+ } else {
301
+ // if object, extract keys, in enumeration order, unsorted
302
+ optionValuesKeys = [ ] ;
303
+ for ( var itemKey in optionValues ) {
304
+ if ( optionValues . hasOwnProperty ( itemKey ) && itemKey . charAt ( 0 ) !== '$' ) {
305
+ optionValuesKeys . push ( itemKey ) ;
306
+ }
307
+ }
308
+ }
309
+ return optionValuesKeys ;
310
+ }
311
+
295
312
return {
296
313
trackBy : trackBy ,
297
314
getTrackByValue : getTrackByValue ,
298
- getWatchables : $parse ( valuesFn , function ( values ) {
315
+ getWatchables : $parse ( valuesFn , function ( optionValues ) {
299
316
// Create a collection of things that we would like to watch (watchedArray)
300
317
// so that they can all be watched using a single $watchCollection
301
318
// that only runs the handler once if anything changes
302
319
var watchedArray = [ ] ;
303
- values = values || [ ] ;
320
+ optionValues = optionValues || [ ] ;
304
321
305
- Object . keys ( values ) . forEach ( function getWatchable ( key ) {
306
- if ( key . charAt ( 0 ) === '$' ) return ;
307
- var locals = getLocals ( values [ key ] , key ) ;
308
- var selectValue = getTrackByValueFn ( values [ key ] , locals ) ;
322
+ var optionValuesKeys = getOptionValuesKeys ( optionValues ) ;
323
+ var optionValuesLength = optionValuesKeys . length ;
324
+ for ( var index = 0 ; index < optionValuesLength ; index ++ ) {
325
+ var key = ( optionValues === optionValuesKeys ) ? index : optionValuesKeys [ index ] ;
326
+ var value = optionValues [ key ] ;
327
+
328
+ var locals = getLocals ( optionValues [ key ] , key ) ;
329
+ var selectValue = getTrackByValueFn ( optionValues [ key ] , locals ) ;
309
330
watchedArray . push ( selectValue ) ;
310
331
311
332
// Only need to watch the displayFn if there is a specific label expression
@@ -319,7 +340,7 @@ var ngOptionsDirective = ['$compile', '$parse', function($compile, $parse) {
319
340
var disableWhen = disableWhenFn ( scope , locals ) ;
320
341
watchedArray . push ( disableWhen ) ;
321
342
}
322
- } ) ;
343
+ }
323
344
return watchedArray ;
324
345
} ) ,
325
346
@@ -331,21 +352,7 @@ var ngOptionsDirective = ['$compile', '$parse', function($compile, $parse) {
331
352
// The option values were already computed in the `getWatchables` fn,
332
353
// which must have been called to trigger `getOptions`
333
354
var optionValues = valuesFn ( scope ) || [ ] ;
334
- var optionValuesKeys ;
335
-
336
-
337
- if ( ! keyName && isArrayLike ( optionValues ) ) {
338
- optionValuesKeys = optionValues ;
339
- } else {
340
- // if object, extract keys, in enumeration order, unsorted
341
- optionValuesKeys = [ ] ;
342
- for ( var itemKey in optionValues ) {
343
- if ( optionValues . hasOwnProperty ( itemKey ) && itemKey . charAt ( 0 ) !== '$' ) {
344
- optionValuesKeys . push ( itemKey ) ;
345
- }
346
- }
347
- }
348
-
355
+ var optionValuesKeys = getOptionValuesKeys ( optionValues ) ;
349
356
var optionValuesLength = optionValuesKeys . length ;
350
357
351
358
for ( var index = 0 ; index < optionValuesLength ; index ++ ) {
0 commit comments