@@ -230,6 +230,17 @@ var NG_OPTIONS_REGEXP = /^\s*([\s\S]+?)(?:\s+as\s+([\s\S]+?))?(?:\s+group\s+by\s
230
230
231
231
var ngOptionsDirective = [ '$compile' , '$parse' , function ( $compile , $parse ) {
232
232
233
+ function iterateOverObjectProperties ( obj , fn ) {
234
+ // extract keys, in enumeration order, unsorted
235
+ var keys = Object . keys ( obj ) ;
236
+ keys . forEach ( function ( key ) {
237
+ if ( key . charAt ( 0 ) !== '$' ) {
238
+ fn ( obj [ key ] , key ) ;
239
+ }
240
+ } ) ;
241
+ }
242
+
243
+
233
244
function parseOptionsExpression ( optionsExp , selectElement , scope ) {
234
245
235
246
var match = optionsExp . match ( NG_OPTIONS_REGEXP ) ;
@@ -321,30 +332,11 @@ var ngOptionsDirective = ['$compile', '$parse', function($compile, $parse) {
321
332
322
333
var optionItems = [ ] ;
323
334
var selectValueMap = { } ;
324
-
325
- // The option values were already computed in the `getWatchables` fn,
326
- // which must have been called to trigger `getOptions`
327
335
var optionValues = valuesFn ( scope ) || [ ] ;
328
- var optionValuesKeys ;
336
+ var forEachOptionValue = ( ! keyName && isArrayLike ( optionValues ) ) ? forEach : iterateOverObjectProperties ;
329
337
330
338
331
- if ( ! keyName && isArrayLike ( optionValues ) ) {
332
- optionValuesKeys = optionValues ;
333
- } else {
334
- // if object, extract keys, in enumeration order, unsorted
335
- optionValuesKeys = [ ] ;
336
- for ( var itemKey in optionValues ) {
337
- if ( optionValues . hasOwnProperty ( itemKey ) && itemKey . charAt ( 0 ) !== '$' ) {
338
- optionValuesKeys . push ( itemKey ) ;
339
- }
340
- }
341
- }
342
-
343
- var optionValuesLength = optionValuesKeys . length ;
344
-
345
- for ( var index = 0 ; index < optionValuesLength ; index ++ ) {
346
- var key = ( optionValues === optionValuesKeys ) ? index : optionValuesKeys [ index ] ;
347
- var value = optionValues [ key ] ;
339
+ forEachOptionValue ( optionValues , function ( value , key ) {
348
340
var locals = getLocals ( value , key ) ;
349
341
var viewValue = viewValueFn ( scope , locals ) ;
350
342
var selectValue = getTrackByValue ( viewValue , locals ) ;
@@ -355,7 +347,7 @@ var ngOptionsDirective = ['$compile', '$parse', function($compile, $parse) {
355
347
356
348
optionItems . push ( optionItem ) ;
357
349
selectValueMap [ selectValue ] = optionItem ;
358
- }
350
+ } ) ;
359
351
360
352
return {
361
353
items : optionItems ,
0 commit comments