@@ -212,17 +212,19 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
212
212
var NG_REMOVED = '$$NG_REMOVED' ;
213
213
var ngRepeatMinErr = minErr ( 'ngRepeat' ) ;
214
214
215
- var updateScope = function ( scope , index , valueIdentifier , value , keyIdentifier , key , arrayLength ) {
215
+ var updateScope = function ( scope , index , valueIdentifier , value , keyIdentifier , key , arrayLength , aliasAs , LocalAlias ) {
216
+ var aliasRef = aliasAs ? new LocalAlias ( ) : { } ;
216
217
// TODO(perf): generate setters to shave off ~40ms or 1-1.5%
217
218
scope [ valueIdentifier ] = value ;
218
219
if ( keyIdentifier ) scope [ keyIdentifier ] = key ;
219
- scope . $index = index ;
220
- scope . $first = ( index === 0 ) ;
221
- scope . $last = ( index === ( arrayLength - 1 ) ) ;
222
- scope . $middle = ! ( scope . $first || scope . $last ) ;
220
+ aliasRef . $index = scope . $index = index ;
221
+ aliasRef . $first = scope . $first = ( index === 0 ) ;
222
+ aliasRef . $last = scope . $last = ( index === ( arrayLength - 1 ) ) ;
223
+ aliasRef . $middle = scope . $middle = ! ( scope . $first || scope . $last ) ;
223
224
// jshint bitwise: false
224
- scope . $odd = ! ( scope . $even = ( index & 1 ) === 0 ) ;
225
+ aliasRef . $odd = scope . $odd = ! ( aliasRef . $even = scope . $even = ( index & 1 ) === 0 ) ;
225
226
// jshint bitwise: true
227
+ if ( aliasAs ) scope [ aliasAs ] = aliasRef ;
226
228
} ;
227
229
228
230
var getBlockStart = function ( block ) {
@@ -328,6 +330,7 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
328
330
329
331
if ( aliasAs ) {
330
332
$scope [ aliasAs ] = collection ;
333
+ LocalAlias . prototype = collection ;
331
334
}
332
335
333
336
if ( isArrayLike ( collection ) ) {
@@ -411,7 +414,7 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
411
414
$animate . move ( getBlockNodes ( block . clone ) , null , jqLite ( previousNode ) ) ;
412
415
}
413
416
previousNode = getBlockEnd ( block ) ;
414
- updateScope ( block . scope , index , valueIdentifier , value , keyIdentifier , key , collectionLength ) ;
417
+ updateScope ( block . scope , index , valueIdentifier , value , keyIdentifier , key , collectionLength , aliasAs , LocalAlias ) ;
415
418
} else {
416
419
// new item which we don't know about
417
420
$transclude ( function ngRepeatTransclude ( clone , scope ) {
@@ -428,11 +431,13 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
428
431
// by a directive with templateUrl when its template arrives.
429
432
block . clone = clone ;
430
433
nextBlockMap [ block . id ] = block ;
431
- updateScope ( block . scope , index , valueIdentifier , value , keyIdentifier , key , collectionLength ) ;
434
+ updateScope ( block . scope , index , valueIdentifier , value , keyIdentifier , key , collectionLength , aliasAs , LocalAlias ) ;
432
435
} ) ;
433
436
}
434
437
}
435
438
lastBlockMap = nextBlockMap ;
439
+
440
+ function LocalAlias ( ) { }
436
441
} ) ;
437
442
} ;
438
443
}
0 commit comments