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

fix(ngView): use animation promises ensure that only one leave animation... #9374

Merged
merged 1 commit into from
Oct 1, 2014
Merged
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
15 changes: 8 additions & 7 deletions src/ngRoute/directive/ngView.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,27 +188,28 @@ function ngViewFactory( $route, $anchorScroll, $animate) {
link: function(scope, $element, attr, ctrl, $transclude) {
var currentScope,
currentElement,
previousElement,
previousLeaveAnimation,
autoScrollExp = attr.autoscroll,
onloadExp = attr.onload || '';

scope.$on('$routeChangeSuccess', update);
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;
}
}
Expand Down
18 changes: 4 additions & 14 deletions test/ngRoute/directive/ngViewSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
'<div>' +
Expand Down Expand Up @@ -884,8 +874,8 @@ describe('ngView animations', function() {
$rootScope.$digest();

expect(destroyed).toBe(true);
});
});
})
);
});


Expand Down