@@ -345,7 +345,9 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
345
345
// We try to reuse these if possible
346
346
// - optionGroupsCache[0] is the options with no option group
347
347
// - optionGroupsCache[?][0] is the parent: either the SELECT or OPTGROUP element
348
- optionGroupsCache = [ [ { element : selectElement , label :'' } ] ] ;
348
+ optionGroupsCache = [ [ { element : selectElement , label :'' } ] ] ,
349
+ //re-usable object to represent option's locals
350
+ locals = { } ;
349
351
350
352
if ( nullOption ) {
351
353
// compile the element since there might be bindings in it
@@ -367,7 +369,6 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
367
369
scope . $apply ( function ( ) {
368
370
var optionGroup ,
369
371
collection = valuesFn ( scope ) || [ ] ,
370
- locals = { } ,
371
372
key , value , optionElement , index , groupIndex , length , groupLength , trackIndex ;
372
373
var selectedKeys = selectElement . val ( ) ;
373
374
var viewValue ;
@@ -388,8 +389,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
388
389
389
390
scope . $watchCollection ( valuesFn , scheduleRendering ) ;
390
391
scope . $watchCollection ( function ( ) {
391
- var locals = { } ,
392
- values = valuesFn ( scope ) ;
392
+ var values = valuesFn ( scope ) ;
393
393
if ( values ) {
394
394
var toDisplay = new Array ( values . length ) ;
395
395
for ( var i = 0 , ii = values . length ; i < ii ; i ++ ) {
@@ -411,7 +411,6 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
411
411
var viewValue = ctrl . $viewValue ;
412
412
if ( trackFn && isArray ( viewValue ) && ! selectAs ) {
413
413
selectedSet = new HashMap ( [ ] ) ;
414
- var locals = { } ;
415
414
for ( var trackIndex = 0 ; trackIndex < viewValue . length ; trackIndex ++ ) {
416
415
locals [ valueName ] = viewValue [ trackIndex ] ;
417
416
selectedSet . put ( trackFn ( scope , locals ) , viewValue [ trackIndex ] ) ;
@@ -436,8 +435,6 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
436
435
437
436
// TODO: Use this method everywhere
438
437
function callExpression ( exprFn , key , collection ) {
439
- // TODO: keep this as a central object, no need to recreate this
440
- var locals = { } ;
441
438
locals [ valueName ] = collection [ key ] ;
442
439
if ( keyName ) locals [ keyName ] = key ;
443
440
return exprFn ( scope , locals ) ;
@@ -489,7 +486,6 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
489
486
key ,
490
487
groupLength , length ,
491
488
groupIndex , index ,
492
- locals = { } ,
493
489
selected ,
494
490
selectedSet = getSelectedSet ( ) ,
495
491
lastElement ,
@@ -502,10 +498,10 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
502
498
if ( keyName ) {
503
499
key = keys [ index ] ;
504
500
if ( key . charAt ( 0 ) === '$' ) continue ;
505
- locals [ keyName ] = key ;
506
501
}
507
502
508
- locals [ valueName ] = values [ key ] ;
503
+ //Called without assigning value to reset properties of locals object
504
+ var optionValue = callExpression ( noop , key , values ) ;
509
505
510
506
optionGroupName = groupByFn ( scope , locals ) || '' ;
511
507
if ( ! ( optionGroup = optionGroups [ optionGroupName ] ) ) {
0 commit comments