@@ -264,7 +264,6 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
264
264
// lastBlockMap on the next iteration.
265
265
nextBlockMap = { } ,
266
266
arrayLength ,
267
- childScope ,
268
267
key , value , // key/value of iteration
269
268
trackById ,
270
269
trackByIdFn ,
@@ -273,6 +272,17 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
273
272
nextBlockOrder = [ ] ,
274
273
elementsToRemove ;
275
274
275
+ var updateScope = function ( scope , index ) {
276
+ scope [ valueIdentifier ] = value ;
277
+ if ( keyIdentifier ) scope [ keyIdentifier ] = key ;
278
+ scope . $index = index ;
279
+ scope . $first = ( index === 0 ) ;
280
+ scope . $last = ( index === ( arrayLength - 1 ) ) ;
281
+ scope . $middle = ! ( scope . $first || scope . $last ) ;
282
+ // jshint bitwise: false
283
+ scope . $odd = ! ( scope . $even = ( index & 1 ) === 0 ) ;
284
+ // jshint bitwise: true
285
+ } ;
276
286
277
287
if ( isArrayLike ( collection ) ) {
278
288
collectionKeys = collection ;
@@ -340,8 +350,6 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
340
350
if ( block . scope ) {
341
351
// if we have already seen this object, then we need to reuse the
342
352
// associated scope/element
343
- childScope = block . scope ;
344
-
345
353
nextNode = previousNode ;
346
354
do {
347
355
nextNode = nextNode . nextSibling ;
@@ -354,32 +362,19 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
354
362
previousNode = getBlockEnd ( block ) ;
355
363
} else {
356
364
// new item which we don't know about
357
- childScope = $scope . $new ( ) ;
358
- }
359
-
360
- childScope [ valueIdentifier ] = value ;
361
- if ( keyIdentifier ) childScope [ keyIdentifier ] = key ;
362
- childScope . $index = index ;
363
- childScope . $first = ( index === 0 ) ;
364
- childScope . $last = ( index === ( arrayLength - 1 ) ) ;
365
- childScope . $middle = ! ( childScope . $first || childScope . $last ) ;
366
- // jshint bitwise: false
367
- childScope . $odd = ! ( childScope . $even = ( index & 1 ) === 0 ) ;
368
- // jshint bitwise: true
369
-
370
- if ( ! block . scope ) {
371
- $transclude ( childScope , function ( clone ) {
365
+ $transclude ( function ( clone , scope ) {
366
+ block . scope = scope ;
372
367
clone [ clone . length ++ ] = document . createComment ( ' end ngRepeat: ' + expression + ' ' ) ;
373
368
$animate . enter ( clone , null , jqLite ( previousNode ) ) ;
374
369
previousNode = clone ;
375
- block . scope = childScope ;
376
370
// Note: We only need the first/last node of the cloned nodes.
377
371
// However, we need to keep the reference to the jqlite wrapper as it might be changed later
378
372
// by a directive with templateUrl when it's template arrives.
379
373
block . clone = clone ;
380
374
nextBlockMap [ block . id ] = block ;
381
375
} ) ;
382
376
}
377
+ updateScope ( block . scope , index ) ;
383
378
}
384
379
lastBlockMap = nextBlockMap ;
385
380
} ) ;
0 commit comments