From 77350209aac72dcb888fd0cd23061fbeaab43933 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Tue, 9 Sep 2014 02:52:36 +0200 Subject: [PATCH] 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 --- src/ng/directive/ngRepeat.js | 2 +- test/ng/directive/ngRepeatSpec.js | 40 +++++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/ng/directive/ngRepeat.js b/src/ng/directive/ngRepeat.js index f1fb5a3a..3ab8e3b1 100644 --- a/src/ng/directive/ngRepeat.js +++ b/src/ng/directive/ngRepeat.js @@ -379,7 +379,7 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) { block = lastBlockMap[blockKey]; elementsToRemove = getBlockNodes(block.clone); $animate.leave(elementsToRemove); - if (elementsToRemove[0].parent) { + if (elementsToRemove[0].parentNode) { // if the element was not removed yet because of pending animation, mark it as deleted // so that we can ignore it later for (index = 0, length = elementsToRemove.length; index < length; index++) { diff --git a/test/ng/directive/ngRepeatSpec.js b/test/ng/directive/ngRepeatSpec.js index 7cf16923..e3e69b0e 100644 --- a/test/ng/directive/ngRepeatSpec.js +++ b/test/ng/directive/ngRepeatSpec.js @@ -1364,6 +1364,7 @@ describe('ngRepeat animations', function() { return element; } + beforeEach(module('ngAnimate')); beforeEach(module('ngAnimateMock')); beforeEach(module(function() { @@ -1376,8 +1377,7 @@ describe('ngRepeat animations', function() { })); afterEach(function(){ - dealoc(body); - dealoc(element); + body.empty(); }); it('should fire off the enter animation', @@ -1445,6 +1445,42 @@ describe('ngRepeat animations', function() { expect(item.element.text()).toBe('2'); })); + it('should not change the position of the block that is being animated away via a leave animation', + inject(function($compile, $rootScope, $animate, $document, $window, $sniffer, $timeout) { + if (!$sniffer.transitions) return; + + var item; + var ss = createMockStyleSheet($document, $window); + + try { + + $animate.enabled(true); + + ss.addRule('.animate-me div', + '-webkit-transition:1s linear all; transition:1s linear all;'); + + element = $compile(html('
' + + '
{{ item }}
' + + '
'))($rootScope); + + $rootScope.items = ['1','2','3']; + $rootScope.$digest(); + expect(element.text()).toBe('123'); + + $rootScope.items = ['1','3']; + $rootScope.$digest(); + + expect(element.text()).toBe('123'); // the original order should be preserved + $animate.triggerReflow(); + $timeout.flush(1500); // 1s * 1.5 closing buffer + expect(element.text()).toBe('13'); + + } finally { + ss.destroy(); + } + }) + ); + it('should fire off the move animation', inject(function($compile, $rootScope, $animate) {