211
211
var ngRepeatDirective = [ '$parse' , '$animate' , function ( $parse , $animate ) {
212
212
var NG_REMOVED = '$$NG_REMOVED' ;
213
213
var ngRepeatMinErr = minErr ( 'ngRepeat' ) ;
214
+ var nullAliasProperties = { } ;
214
215
215
- var updateScope = function ( scope , index , valueIdentifier , value , keyIdentifier , key , arrayLength ) {
216
+ var updateScope = function ( scope , index , valueIdentifier , value , keyIdentifier , key , arrayLength , aliasAs ) {
217
+ var aliasRef = aliasAs ? { } : nullAliasProperties ;
216
218
// TODO(perf): generate setters to shave off ~40ms or 1-1.5%
217
219
scope [ valueIdentifier ] = value ;
218
220
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 ) ;
221
+ aliasRef . $index = scope . $index = index ;
222
+ aliasRef . $first = scope . $first = ( index === 0 ) ;
223
+ aliasRef . $last = scope . $last = ( index === ( arrayLength - 1 ) ) ;
224
+ aliasRef . $middle = scope . $middle = ! ( scope . $first || scope . $last ) ;
223
225
// jshint bitwise: false
224
- scope . $odd = ! ( scope . $even = ( index & 1 ) === 0 ) ;
226
+ aliasRef . $odd = scope . $odd = ! ( aliasRef . $even = scope . $even = ( index & 1 ) === 0 ) ;
225
227
// jshint bitwise: true
228
+ if ( aliasAs ) scope [ '$' + aliasAs ] = aliasRef ;
226
229
} ;
227
230
228
231
var getBlockStart = function ( block ) {
@@ -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 ) ;
415
418
} else {
416
419
// new item which we don't know about
417
420
$transclude ( function ngRepeatTransclude ( clone , scope ) {
@@ -428,7 +431,7 @@ 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 ) ;
432
435
} ) ;
433
436
}
434
437
}
0 commit comments