@@ -454,6 +454,13 @@ var ngRepeatDirective = ['$parse', '$animate', '$compile', function($parse, $ani
454
454
return block . clone [ block . clone . length - 1 ] ;
455
455
} ;
456
456
457
+ var trackByIdArrayFn = function ( $scope , key , value ) {
458
+ return hashKey ( value ) ;
459
+ } ;
460
+
461
+ var trackByIdObjFn = function ( $scope , key ) {
462
+ return key ;
463
+ } ;
457
464
458
465
return {
459
466
restrict : 'A' ,
@@ -493,32 +500,23 @@ var ngRepeatDirective = ['$parse', '$animate', '$compile', function($parse, $ani
493
500
aliasAs ) ;
494
501
}
495
502
496
- var trackByExpGetter , trackByIdExpFn , trackByIdArrayFn , trackByIdObjFn ;
497
- var hashFnLocals = { $id : hashKey } ;
503
+ var trackByIdExpFn ;
498
504
499
505
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 ) ;
507
515
} ;
508
516
}
509
517
510
518
return function ngRepeatLink ( $scope , $element , $attr , ctrl , $transclude ) {
511
519
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
-
522
520
// Store a list of elements from previous run. This is a hash where key is the item from the
523
521
// iterator, and the value is objects with following properties.
524
522
// - scope: bound scope
@@ -572,7 +570,7 @@ var ngRepeatDirective = ['$parse', '$animate', '$compile', function($parse, $ani
572
570
for ( index = 0 ; index < collectionLength ; index ++ ) {
573
571
key = ( collection === collectionKeys ) ? index : collectionKeys [ index ] ;
574
572
value = collection [ key ] ;
575
- trackById = trackByIdFn ( key , value , index ) ;
573
+ trackById = trackByIdFn ( $scope , key , value , index ) ;
576
574
if ( lastBlockMap [ trackById ] ) {
577
575
// found previously seen block
578
576
block = lastBlockMap [ trackById ] ;
0 commit comments