-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat(ngRepeat): add $prev and $next properties to ngRepeat #9795
Conversation
- Adds 2 new properties to ngRepeat item scopes: $prev and $next - Adds tests to corresponding changes - Makes simple refactoring on comparison used couple of times for better readability Closes angular#9740
@kwypchlo this is a nice patch with all the tests, doc update and all - good job! So on this ground it could be merged but I wonder what is the functional use-case here. I mean, I can see what you are proposing but would like to see how it makes your application code easier in your particular case. Could you please elaborate on how did you bump into the need for $prev / $next? This would help us justify additional bytes / complexity in ngRepeat. Thnx! |
@pkozlowski-opensource well my PR is more of a reply to #9740 so maybe @lukehorvat could elaborate an example. I kind of just wanted to contribute something and it looked like a nice feature to help out :) Theoretically, $prev and $next could be beneficial on cases where you would depend on some comparison between a previous or next value. |
Nice work @kwypchlo! @pkozlowski-opensource I think the primary use case for it would be to render "differences" between adjacent items in a collection (which, incidentally, I've had to do in the last three Angular apps that I've built). For example: In this example, I reference the previous item in an ngClass expression to draw the up/down arrow, and again in a string interpolation to display the percentage number. Doing It's definitely not an absolutely necessary feature, because |
I recently would have found such a feature quite useful, too, so it's get a +1 from me. |
I like it! It can be used to create headers as well, see issue #10362 . I was thinking the same, but this looks more mature and better, so i'll start using this! |
+1 Recently, in order to render a flat list grouped by type, with a header, I resorted to group data first with lodash and then apply 2ng-repeat. This PR could make this scenario simpler I think. |
I wonder if this could be done nicely using a directive... http://plnkr.co/edit/w4e1KfZwlo1L5LFCSzaM?p=preview Or even better if we provided an |
It is nice as a directive. It can be used to even fake groupings, although there are some gotchas: http://plnkr.co/edit/Z7WQHODEXNzHKymZHOnd?p=preview |
Well I'm going to close this one since it seems it is not going to be merged anyway. |
Closes #9740