Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
/angular.jsPublic archive

Commitc969ae2

Browse files
committed
fix(ngRepeat): correctly re-create last block order when track by is an integer
Merge changes fromNarretz@7dbf428.
1 parentdcc80c1 commitc969ae2

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

‎src/ng/directive/ngRepeat.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,9 +485,9 @@ var ngRepeatDirective = ['$parse', '$animate', '$compile', function($parse, $ani
485485
nextBlockOrder[index]=trackById;
486486
}
487487

488-
//setuplastBlockOrder, used to determine if block moved
488+
//Set uplastBlockOrder. Used to determine ifablock moved.
489489
for(keyinlastBlockMap){
490-
lastBlockOrder.push(key);
490+
lastBlockOrder[lastBlockMap[key].index]=key;
491491
}
492492

493493
for(index=0;index<nextLength;index++){

‎test/ng/directive/ngRepeatSpec.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,4 +1624,55 @@ describe('ngRepeat animations', function() {
16241624
expect(item.element.text()).toBe('2');
16251625
})
16261626
);
1627+
it('should maintain the order when the track by expression evaluates to an integer',
1628+
inject(function($compile,$rootScope,$animate,$document,$sniffer,$timeout){
1629+
if(!$sniffer.transitions)return;
1630+
1631+
varitem;
1632+
varss=createMockStyleSheet($document);
1633+
1634+
varitems=[
1635+
{id:1,name:'A'},
1636+
{id:2,name:'B'},
1637+
{id:4,name:'C'},
1638+
{id:3,name:'D'}
1639+
];
1640+
1641+
try{
1642+
1643+
$animate.enabled(true);
1644+
1645+
ss.addRule('.animate-me div',
1646+
'transition:1s linear all;');
1647+
1648+
element=$compile(html('<div class="animate-me">'+
1649+
'<div ng-repeat="item in items track by item.id">{{ item.name }}</div>'+
1650+
'</div>'))($rootScope);
1651+
1652+
$rootScope.items=[items[0],items[1],items[2]];
1653+
$rootScope.$digest();
1654+
expect(element.text()).toBe('ABC');
1655+
1656+
$rootScope.items.push(items[3]);
1657+
$rootScope.$digest();
1658+
1659+
expect(element.text()).toBe('ABCD');// the original order should be preserved
1660+
$animate.flush();
1661+
$timeout.flush(1500);// 1s * 1.5 closing buffer
1662+
expect(element.text()).toBe('ABCD');
1663+
1664+
$rootScope.items=[items[0],items[1],items[3]];
1665+
$rootScope.$digest();
1666+
1667+
// The leaving item should maintain it's position until it is removed
1668+
expect(element.text()).toBe('ABCD');
1669+
$animate.flush();
1670+
$timeout.flush(1500);// 1s * 1.5 closing buffer
1671+
expect(element.text()).toBe('ABD');
1672+
1673+
}finally{
1674+
ss.destroy();
1675+
}
1676+
})
1677+
);
16271678
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp