diff --git a/src/ngAnimate/animate.js b/src/ngAnimate/animate.js index 2e67aa89e330..9f09d4aaf223 100644 --- a/src/ngAnimate/animate.js +++ b/src/ngAnimate/animate.js @@ -958,10 +958,9 @@ angular.module('ngAnimate', ['ng']) //cancel all animations when a structural animation takes place for(var klass in runningAnimations) { animationsToCancel.push(runningAnimations[klass]); - cleanup(element, klass); } - runningAnimations = {}; - totalActiveAnimations = 0; + ngAnimateState = {}; + cleanup(element, true); } } else if(lastAnimation.event == 'setClass') { animationsToCancel.push(lastAnimation); @@ -984,6 +983,9 @@ angular.module('ngAnimate', ['ng']) } } + runningAnimations = ngAnimateState.active || {}; + totalActiveAnimations = ngAnimateState.totalActive || 0; + if(runner.isClassBased && !runner.isSetClassOperation && !skipAnimation) { skipAnimation = (animationEvent == 'addClass') == element.hasClass(className); //opposite of XOR } diff --git a/test/ngAnimate/animateSpec.js b/test/ngAnimate/animateSpec.js index 737d2f1d0323..b590f1d31a3b 100644 --- a/test/ngAnimate/animateSpec.js +++ b/test/ngAnimate/animateSpec.js @@ -690,6 +690,46 @@ describe("ngAnimate", function() { expect(child.hasClass('animation-cancelled')).toBe(true); })); + it("should remove the .ng-animate class after the next animation is run which interrupted the last animation", function() { + var addClassDone, removeClassDone, + addClassDoneSpy = jasmine.createSpy(), + removeClassDoneSpy = jasmine.createSpy(); + + module(function($animateProvider) { + $animateProvider.register('.hide', function() { + return { + addClass : function(element, className, done) { + addClassDone = done; + return addClassDoneSpy; + }, + removeClass : function(element, className, done) { + removeClassDone = done; + return removeClassDoneSpy; + } + }; + }); + }); + + inject(function($animate, $rootScope, $sniffer, $timeout) { + $animate.addClass(element, 'hide'); + + expect(element).toHaveClass('ng-animate'); + + $animate.triggerReflow(); + + $animate.removeClass(element, 'hide'); + expect(addClassDoneSpy).toHaveBeenCalled(); + + $animate.triggerReflow(); + + expect(element).toHaveClass('ng-animate'); + + removeClassDone(); + $animate.triggerCallbacks(); + + expect(element).not.toHaveClass('ng-animate'); + }); + }); it("should skip a class-based animation if the same element already has an ongoing structural animation", inject(function($animate, $rootScope, $sniffer, $timeout) {