@@ -454,6 +454,13 @@ var ngRepeatDirective = ['$parse', '$animate', '$compile', function($parse, $ani
454454 return block . clone [ block . clone . length - 1 ] ;
455455 } ;
456456
457+ var trackByIdArrayFn = function ( $scope , key , value ) {
458+ return hashKey ( value ) ;
459+ } ;
460+
461+ var trackByIdObjFn = function ( $scope , key ) {
462+ return key ;
463+ } ;
457464
458465 return {
459466 restrict : 'A' ,
@@ -493,32 +500,23 @@ var ngRepeatDirective = ['$parse', '$animate', '$compile', function($parse, $ani
493500 aliasAs ) ;
494501 }
495502
496- var trackByExpGetter , trackByIdExpFn , trackByIdArrayFn , trackByIdObjFn ;
497- var hashFnLocals = { $id : hashKey } ;
503+ var trackByIdExpFn ;
498504
499505 if ( trackByExp ) {
500- trackByExpGetter = $parse ( trackByExp ) ;
501- } else {
502- trackByIdArrayFn = function ( key , value ) {
503- return hashKey ( value ) ;
504- } ;
505- trackByIdObjFn = function ( key ) {
506- return key ;
506+ var hashFnLocals = { $id : hashKey } ;
507+ var trackByExpGetter = $parse ( trackByExp ) ;
508+
509+ trackByIdExpFn = function ( $scope , key , value , index ) {
510+ // assign key, value, and $index to the locals so that they can be used in hash functions
511+ if ( keyIdentifier ) hashFnLocals [ keyIdentifier ] = key ;
512+ hashFnLocals [ valueIdentifier ] = value ;
513+ hashFnLocals . $index = index ;
514+ return trackByExpGetter ( $scope , hashFnLocals ) ;
507515 } ;
508516 }
509517
510518 return function ngRepeatLink ( $scope , $element , $attr , ctrl , $transclude ) {
511519
512- if ( trackByExpGetter ) {
513- trackByIdExpFn = function ( key , value , index ) {
514- // assign key, value, and $index to the locals so that they can be used in hash functions
515- if ( keyIdentifier ) hashFnLocals [ keyIdentifier ] = key ;
516- hashFnLocals [ valueIdentifier ] = value ;
517- hashFnLocals . $index = index ;
518- return trackByExpGetter ( $scope , hashFnLocals ) ;
519- } ;
520- }
521-
522520 // Store a list of elements from previous run. This is a hash where key is the item from the
523521 // iterator, and the value is objects with following properties.
524522 // - scope: bound scope
@@ -572,7 +570,7 @@ var ngRepeatDirective = ['$parse', '$animate', '$compile', function($parse, $ani
572570 for ( index = 0 ; index < collectionLength ; index ++ ) {
573571 key = ( collection === collectionKeys ) ? index : collectionKeys [ index ] ;
574572 value = collection [ key ] ;
575- trackById = trackByIdFn ( key , value , index ) ;
573+ trackById = trackByIdFn ( $scope , key , value , index ) ;
576574 if ( lastBlockMap [ trackById ] ) {
577575 // found previously seen block
578576 block = lastBlockMap [ trackById ] ;
0 commit comments