fix🆖repeater - fix $position when collection size changes

This commit is contained in:
Misko Hevery 2011-06-22 14:30:56 -07:00 committed by Igor Minar
parent 8e880fcb77
commit 9ec45ad5c4
3 changed files with 9 additions and 1 deletions

View file

@ -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

View file

@ -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

View file

@ -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|');
});