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

Commit 2f6b6fb

Browse files
committed
fix($animateCss): do not throw errors when a closing timeout is fired on a removed element
Closes #12650
1 parent ea2518f commit 2f6b6fb

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

src/ngAnimate/animateCss.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -894,10 +894,16 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
894894

895895
function onAnimationExpired() {
896896
var animationsData = element.data(ANIMATE_TIMER_KEY);
897-
for (var i = 1; i < animationsData.length; i++) {
898-
animationsData[i]();
897+
898+
// this will be false in the event that the element was
899+
// removed from the DOM (via a leave animation or something
900+
// similar)
901+
if (animationsData) {
902+
for (var i = 1; i < animationsData.length; i++) {
903+
animationsData[i]();
904+
}
905+
element.removeData(ANIMATE_TIMER_KEY);
899906
}
900-
element.removeData(ANIMATE_TIMER_KEY);
901907
}
902908

903909
function onAnimationProgress(event) {

test/ngAnimate/animateCssSpec.js

+18
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,24 @@ describe("ngAnimate $animateCss", function() {
11981198
return animator;
11991199
}
12001200
}));
1201+
1202+
it("should not throw an error any pending timeout requests resolve after the element has already been removed",
1203+
inject(function($animateCss, $$body, $rootElement, $timeout, $animate) {
1204+
1205+
var element = jqLite('<div></div>');
1206+
$rootElement.append(element);
1207+
$$body.append($rootElement);
1208+
1209+
ss.addRule('.red', 'transition:1s linear all;');
1210+
1211+
$animateCss(element, { addClass: 'red' }).start();
1212+
triggerAnimationStartFrame();
1213+
element.remove();
1214+
1215+
expect(function() {
1216+
$timeout.flush();
1217+
}).not.toThrow();
1218+
}));
12011219
});
12021220

12031221
describe("getComputedStyle", function() {

0 commit comments

Comments
 (0)