Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit ed63733

Browse files
committed
fix(ngRepeat): preserve original position of elements that are being animated away
During the recent refactoring a typo was made that broke code that detects if we are already removed from the DOM (animation has completed). Closes #8918 Closes #8994
1 parent f33a938 commit ed63733

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

src/ng/directive/ngRepeat.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
379379
block = lastBlockMap[blockKey];
380380
elementsToRemove = getBlockNodes(block.clone);
381381
$animate.leave(elementsToRemove);
382-
if (elementsToRemove[0].parent) {
382+
if (elementsToRemove[0].parentNode) {
383383
// if the element was not removed yet because of pending animation, mark it as deleted
384384
// so that we can ignore it later
385385
for (index = 0, length = elementsToRemove.length; index < length; index++) {

test/ng/directive/ngRepeatSpec.js

+38-2
Original file line numberDiff line numberDiff line change
@@ -1365,6 +1365,7 @@ describe('ngRepeat animations', function() {
13651365
return element;
13661366
}
13671367

1368+
beforeEach(module('ngAnimate'));
13681369
beforeEach(module('ngAnimateMock'));
13691370

13701371
beforeEach(module(function() {
@@ -1377,8 +1378,7 @@ describe('ngRepeat animations', function() {
13771378
}));
13781379

13791380
afterEach(function(){
1380-
dealoc(body);
1381-
dealoc(element);
1381+
body.empty();
13821382
});
13831383

13841384
it('should fire off the enter animation',
@@ -1446,6 +1446,42 @@ describe('ngRepeat animations', function() {
14461446
expect(item.element.text()).toBe('2');
14471447
}));
14481448

1449+
it('should not change the position of the block that is being animated away via a leave animation',
1450+
inject(function($compile, $rootScope, $animate, $document, $window, $sniffer, $timeout) {
1451+
if (!$sniffer.transitions) return;
1452+
1453+
var item;
1454+
var ss = createMockStyleSheet($document, $window);
1455+
1456+
try {
1457+
1458+
$animate.enabled(true);
1459+
1460+
ss.addRule('.animate-me div',
1461+
'-webkit-transition:1s linear all; transition:1s linear all;');
1462+
1463+
element = $compile(html('<div class="animate-me">' +
1464+
'<div ng-repeat="item in items">{{ item }}</div>' +
1465+
'</div>'))($rootScope);
1466+
1467+
$rootScope.items = ['1','2','3'];
1468+
$rootScope.$digest();
1469+
expect(element.text()).toBe('123');
1470+
1471+
$rootScope.items = ['1','3'];
1472+
$rootScope.$digest();
1473+
1474+
expect(element.text()).toBe('123'); // the original order should be preserved
1475+
$animate.triggerReflow();
1476+
$timeout.flush(1500); // 1s * 1.5 closing buffer
1477+
expect(element.text()).toBe('13');
1478+
1479+
} finally {
1480+
ss.destroy();
1481+
}
1482+
})
1483+
);
1484+
14491485
it('should fire off the move animation',
14501486
inject(function($compile, $rootScope, $animate) {
14511487

0 commit comments

Comments
 (0)