File tree 2 files changed +27
-0
lines changed
2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change 15
15
* * `$first` – `{boolean}` – true if the repeated element is first in the iterator.
16
16
* * `$middle` – `{boolean}` – true if the repeated element is between the first and last in the iterator.
17
17
* * `$last` – `{boolean}` – true if the repeated element is last in the iterator.
18
+ * * `$keyIdentifier` – `{string}` – Identifier for the key in the (key,value) pair in the expression (if applicable)
19
+ * * `$varIdentifier` – `{string}` – Identifier for the variable in the expression
18
20
*
19
21
*
20
22
* @element ANY
@@ -151,6 +153,8 @@ var ngRepeatDirective = ngDirective({
151
153
childScope . $first = ( index === 0 ) ;
152
154
childScope . $last = ( index === ( collectionLength - 1 ) ) ;
153
155
childScope . $middle = ! ( childScope . $first || childScope . $last ) ;
156
+ childScope . $varIdentifier = valueIdent ;
157
+ if ( keyIdent ) childScope . $keyIdentifier = keyIdent ;
154
158
155
159
if ( ! last ) {
156
160
linker ( childScope , function ( clone ) {
Original file line number Diff line number Diff line change @@ -215,6 +215,29 @@ describe('ngRepeat', function() {
215
215
} ) ;
216
216
217
217
218
+ it ( 'should expose identifier as $varIdentifier when iterating over arrays' ,
219
+ function ( ) {
220
+ element = $compile (
221
+ '<ul>' +
222
+ '<li ng-repeat="item in items">{{item}}:{{$varIdentifier}}:{{$keyIdentifier}}|</li>' +
223
+ '</ul>' ) ( scope ) ;
224
+ scope . items = [ 'misko' , 'shyam' , 'frodo' ] ;
225
+ scope . $digest ( ) ;
226
+ expect ( element . text ( ) ) . toEqual ( 'misko:item:|shyam:item:|frodo:item:|' ) ;
227
+ } ) ;
228
+
229
+
230
+ it ( 'should expose identifiers as $keyIdentifier, $varIdentifier when iterating over objects' , function ( ) {
231
+ element = $compile (
232
+ '<ul>' +
233
+ '<li ng-repeat="(key, val) in items">{{key}}:{{val}}:{{$varIdentifier}}:{{$keyIdentifier}}|</li>' +
234
+ '</ul>' ) ( scope ) ;
235
+ scope . items = { 'misko' :'m' , 'shyam' :'s' , 'frodo' :'f' } ;
236
+ scope . $digest ( ) ;
237
+ expect ( element . text ( ) ) . toEqual ( 'frodo:f:val:key|misko:m:val:key|shyam:s:val:key|' ) ;
238
+ } ) ;
239
+
240
+
218
241
it ( 'should expose iterator offset as $index when iterating over arrays' ,
219
242
function ( ) {
220
243
element = $compile (
You can’t perform that action at this time.
0 commit comments