diff --git a/src/ngRoute/directive/ngView.js b/src/ngRoute/directive/ngView.js index 747a994e3d41..70cbd2330783 100644 --- a/src/ngRoute/directive/ngView.js +++ b/src/ngRoute/directive/ngView.js @@ -188,7 +188,7 @@ function ngViewFactory( $route, $anchorScroll, $animate) { link: function(scope, $element, attr, ctrl, $transclude) { var currentScope, currentElement, - previousElement, + previousLeaveAnimation, autoScrollExp = attr.autoscroll, onloadExp = attr.onload || ''; @@ -196,19 +196,20 @@ function ngViewFactory( $route, $anchorScroll, $animate) { update(); function cleanupLastView() { - if(previousElement) { - previousElement.remove(); - previousElement = null; + if(previousLeaveAnimation) { + $animate.cancel(previousLeaveAnimation); + previousLeaveAnimation = null; } + if(currentScope) { currentScope.$destroy(); currentScope = null; } if(currentElement) { - $animate.leave(currentElement).then(function() { - previousElement = null; + previousLeaveAnimation = $animate.leave(currentElement); + previousLeaveAnimation.then(function() { + previousLeaveAnimation = null; }); - previousElement = currentElement; currentElement = null; } } diff --git a/test/ngRoute/directive/ngViewSpec.js b/test/ngRoute/directive/ngViewSpec.js index 6113a2ca2ec8..3bd63606e62e 100644 --- a/test/ngRoute/directive/ngViewSpec.js +++ b/test/ngRoute/directive/ngViewSpec.js @@ -845,18 +845,8 @@ describe('ngView animations', function() { }); }); - it('should destroy the previous leave animation if a new one takes place', function() { - module(function($provide) { - $provide.decorator('$animate', function($delegate, $$q) { - var emptyPromise = $$q.defer().promise; - $delegate.leave = function() { - return emptyPromise; - }; - return $delegate; - }); - }); - inject(function ($compile, $rootScope, $animate, $location) { - var item; + it('should destroy the previous leave animation if a new one takes place', + inject(function ($compile, $rootScope, $animate, $location, $timeout) { var $scope = $rootScope.$new(); element = $compile(html( '
' + @@ -884,8 +874,8 @@ describe('ngView animations', function() { $rootScope.$digest(); expect(destroyed).toBe(true); - }); - }); + }) + ); });