@@ -233,50 +233,56 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
233
233
priority : 1000 ,
234
234
terminal : true ,
235
235
$$tlb : true ,
236
- link : function ( $scope , $element , $attr , ctrl , $transclude ) {
237
- var expression = $attr . ngRepeat ;
238
- var match = expression . match ( / ^ \s * ( [ \s \S ] + ?) \s + i n \s + ( [ \s \S ] + ?) (?: \s + a s \s + ( [ \s \S ] + ?) ) ? (?: \s + t r a c k \s + b y \s + ( [ \s \S ] + ?) ) ? \s * $ / ) ,
239
- trackByExp , trackByExpGetter , aliasAs , trackByIdExpFn , trackByIdArrayFn , trackByIdObjFn ,
240
- lhs , rhs , valueIdentifier , keyIdentifier ,
241
- hashFnLocals = { $id : hashKey } ;
236
+ compile : function ngRepeatCompile ( $element , $attr ) {
237
+ var expression = $attr . ngRepeat ;
238
+ var ngRepeatEndComment = document . createComment ( ' end ngRepeat: ' + expression + ' ' ) ;
242
239
243
- var ngRepeatEndComment = document . createComment ( ' end ngRepeat: ' + expression + ' ' ) ;
240
+ var match = expression . match ( / ^ \s * ( [ \s \S ] + ? ) \s + i n \s + ( [ \s \S ] + ? ) (?: \s + a s \s + ( [ \s \S ] + ? ) ) ? (?: \s + t r a c k \s + b y \s + ( [ \s \S ] + ? ) ) ? \s * $ / ) ;
244
241
245
- if ( ! match ) {
246
- throw ngRepeatMinErr ( 'iexp' , "Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'." ,
242
+ if ( ! match ) {
243
+ throw ngRepeatMinErr ( 'iexp' , "Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'." ,
247
244
expression ) ;
248
- }
245
+ }
249
246
250
- lhs = match [ 1 ] ;
251
- rhs = match [ 2 ] ;
252
- aliasAs = match [ 3 ] ;
253
- trackByExp = match [ 4 ] ;
247
+ var lhs = match [ 1 ] ;
248
+ var rhs = match [ 2 ] ;
249
+ var aliasAs = match [ 3 ] ;
250
+ var trackByExp = match [ 4 ] ;
254
251
255
- if ( trackByExp ) {
256
- trackByExpGetter = $parse ( trackByExp ) ;
252
+ match = lhs . match ( / ^ (?: ( [ \$ \w ] + ) | \( ( [ \$ \w ] + ) \s * , \s * ( [ \$ \w ] + ) \) ) $ / ) ;
253
+
254
+ if ( ! match ) {
255
+ throw ngRepeatMinErr ( 'iidexp' , "'_item_' in '_item_ in _collection_' should be an identifier or '(_key_, _value_)' expression, but got '{0}'." ,
256
+ lhs ) ;
257
+ }
258
+ var valueIdentifier = match [ 3 ] || match [ 1 ] ;
259
+ var keyIdentifier = match [ 2 ] ;
260
+
261
+ var trackByExpGetter , trackByIdExpFn , trackByIdArrayFn , trackByIdObjFn ;
262
+ var hashFnLocals = { $id : hashKey } ;
263
+
264
+ if ( trackByExp ) {
265
+ trackByExpGetter = $parse ( trackByExp ) ;
266
+ } else {
267
+ trackByIdArrayFn = function ( key , value ) {
268
+ return hashKey ( value ) ;
269
+ } ;
270
+ trackByIdObjFn = function ( key ) {
271
+ return key ;
272
+ } ;
273
+ }
274
+
275
+ return function ngRepeatLink ( $scope , $element , $attr , ctrl , $transclude ) {
276
+
277
+ if ( trackByExpGetter ) {
257
278
trackByIdExpFn = function ( key , value , index ) {
258
279
// assign key, value, and $index to the locals so that they can be used in hash functions
259
280
if ( keyIdentifier ) hashFnLocals [ keyIdentifier ] = key ;
260
281
hashFnLocals [ valueIdentifier ] = value ;
261
282
hashFnLocals . $index = index ;
262
283
return trackByExpGetter ( $scope , hashFnLocals ) ;
263
284
} ;
264
- } else {
265
- trackByIdArrayFn = function ( key , value ) {
266
- return hashKey ( value ) ;
267
- } ;
268
- trackByIdObjFn = function ( key ) {
269
- return key ;
270
- } ;
271
- }
272
-
273
- match = lhs . match ( / ^ (?: ( [ \$ \w ] + ) | \( ( [ \$ \w ] + ) \s * , \s * ( [ \$ \w ] + ) \) ) $ / ) ;
274
- if ( ! match ) {
275
- throw ngRepeatMinErr ( 'iidexp' , "'_item_' in '_item_ in _collection_' should be an identifier or '(_key_, _value_)' expression, but got '{0}'." ,
276
- lhs ) ;
277
285
}
278
- valueIdentifier = match [ 3 ] || match [ 1 ] ;
279
- keyIdentifier = match [ 2 ] ;
280
286
281
287
// Store a list of elements from previous run. This is a hash where key is the item from the
282
288
// iterator, and the value is objects with following properties.
@@ -402,6 +408,7 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
402
408
}
403
409
lastBlockMap = nextBlockMap ;
404
410
} ) ;
411
+ } ;
405
412
}
406
413
} ;
407
414
0 commit comments