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

fix(ngAnimate): ensure that cancelled class-based animations are properly cleaned up #11899

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/ngAnimate/animateQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,13 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
runner.end();
}

// in the event that the element animation was not cancelled or a follow-up animation
// isn't allowed to animate from here then we need to clear the state of the element
// so that any future animations won't read the expired animation data.
if (!isValidAnimation) {
clearElementAnimationState(element);
}

return;
}

Expand Down
16 changes: 16 additions & 0 deletions test/ngAnimate/animateSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,22 @@ describe("animations", function() {

expect(runner1).not.toBe(runner2);
}));

it('should properly cancel out animations when the same class is added/removed within the same digest',
inject(function($animate, $rootScope) {

parent.append(element);
$animate.addClass(element, 'red');
$animate.removeClass(element, 'red');
$rootScope.$digest();

expect(capturedAnimation).toBeFalsy();

$animate.addClass(element, 'blue');
$rootScope.$digest();

expect(capturedAnimation[2].addClass).toBe('blue');
}));
});

describe('should merge', function() {
Expand Down