From 52b8211fd0154b9d6b771a83573a161f5580d92c Mon Sep 17 00:00:00 2001 From: P. Envall Date: Fri, 19 Jul 2013 17:02:17 +0200 Subject: feat(ngRepeat): add $even and $odd props to iterator --- src/ng/directive/ngRepeat.js | 3 ++ test/ng/directive/ngRepeatSpec.js | 63 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/src/ng/directive/ngRepeat.js b/src/ng/directive/ngRepeat.js index b5fa60dd..7da67105 100644 --- a/src/ng/directive/ngRepeat.js +++ b/src/ng/directive/ngRepeat.js @@ -17,6 +17,8 @@ * | `$first` | {@type boolean} | true if the repeated element is first in the iterator. | * | `$middle` | {@type boolean} | true if the repeated element is between the first and last in the iterator. | * | `$last` | {@type boolean} | true if the repeated element is last in the iterator. | + * | `$even` | {@type boolean} | true if the iterator position `$index` is even (otherwise false). | + * | `$odd` | {@type boolean} | true if the iterator position `$index` is odd (otherwise false). | * * Additionally, you can also provide animations via the ngAnimate attribute to animate the **enter**, * **leave** and **move** effects. @@ -354,6 +356,7 @@ var ngRepeatDirective = ['$parse', '$animator', function($parse, $animator) { childScope.$first = (index === 0); childScope.$last = (index === (arrayLength - 1)); childScope.$middle = !(childScope.$first || childScope.$last); + childScope.$odd = !(childScope.$even = index%2==0); if (!block.startNode) { linker(childScope, function(clone) { diff --git a/test/ng/directive/ngRepeatSpec.js b/test/ng/directive/ngRepeatSpec.js index 0d1833c8..26562f4e 100644 --- a/test/ng/directive/ngRepeatSpec.js +++ b/test/ng/directive/ngRepeatSpec.js @@ -353,7 +353,6 @@ describe('ngRepeat', function() { expect(element.text()).toEqual('misko:0|shyam:1|frodo:2|'); }); - it('should expose iterator offset as $index when iterating over objects', function() { element = $compile( '