mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-18 15:50:22 +00:00
fix🆖repeater - fix $position when collection size changes
This commit is contained in:
parent
8e880fcb77
commit
9ec45ad5c4
3 changed files with 9 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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|');
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue