diff options
| author | Misko Hevery | 2011-06-22 14:30:56 -0700 |
|---|---|---|
| committer | Igor Minar | 2011-06-23 08:12:01 -0700 |
| commit | 9ec45ad5c45791c81d4d1909ea1abceedc5ed3e9 (patch) | |
| tree | 0e23535f4388c5bbdc5c183cbfe4e1e558fe4d38 | |
| parent | 8e880fcb77bdcca2fd4a25f1333acc45dca75d8b (diff) | |
| download | angular.js-9ec45ad5c45791c81d4d1909ea1abceedc5ed3e9.tar.bz2 | |
fix:ng:repeater - fix $position when collection size changes
| -rw-r--r-- | CHANGELOG.md | 1 | ||||
| -rw-r--r-- | src/widgets.js | 3 | ||||
| -rw-r--r-- | test/widgetsSpec.js | 6 |
3 files changed, 9 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index b56a8bd6..b46b3c2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ ### Bug Fixes - Number filter would return incorrect value when fractional part had leading zeros. - Issue #399: return unsorted array if no predicate +- Fixed issues with incorrect value of $position in ng:repeat when collection size changes ### Breaking changes diff --git a/src/widgets.js b/src/widgets.js index a9d42bdf..392771e3 100644 --- a/src/widgets.js +++ b/src/widgets.js @@ -1143,6 +1143,9 @@ angularWidget('@ng:repeat', function(expression, element){ childScope[valueIdent] = collection[key]; if (keyIdent) childScope[keyIdent] = key; lastIterElement = childScope.$element; + childScope.$position = index == 0 + ? 'first' + : (index == collectionLength - 1 ? 'last' : 'middle'); childScope.$eval(); } else { // grow children diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index d3b2ec5d..aadc1597 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -893,7 +893,11 @@ describe("widget", function(){ it('should expose iterator position as $position when iterating over arrays', function() { var scope = compile('<ul><li ng:repeat="item in items" ' + 'ng:bind="item + \':\' + $position + \'|\'"></li></ul>'); - scope.items = ['misko', 'shyam', 'doug', 'frodo']; + scope.items = ['misko', 'shyam', 'doug']; + scope.$eval(); + expect(element.text()).toEqual('misko:first|shyam:middle|doug:last|'); + + scope.items.push('frodo'); scope.$eval(); expect(element.text()).toEqual('misko:first|shyam:middle|doug:middle|frodo:last|'); }); |
