Skip to content

Commit b117496

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

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
@@ -895,10 +895,16 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
895895

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

904910
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)