Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ef82e07

Browse files
committedOct 1, 2014
fix(ngView): use animation promises ensure that only one leave animation occurs at a time
the tracking depended on a local flag variable, which was susceptible to corruption due to race conditions. Closes angular#9355 Closes angular#7606
1 parent b1ee538 commit ef82e07

File tree

2 files changed

+10
-20
lines changed

2 files changed

+10
-20
lines changed
 

‎src/ngRoute/directive/ngView.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -188,27 +188,27 @@ function ngViewFactory( $route, $anchorScroll, $animate) {
188188
link: function(scope, $element, attr, ctrl, $transclude) {
189189
var currentScope,
190190
currentElement,
191-
previousElement,
191+
previousLeaveAnimation,
192192
autoScrollExp = attr.autoscroll,
193193
onloadExp = attr.onload || '';
194194

195195
scope.$on('$routeChangeSuccess', update);
196196
update();
197197

198198
function cleanupLastView() {
199-
if(previousElement) {
200-
previousElement.remove();
201-
previousElement = null;
199+
if(previousLeaveAnimation) {
200+
$animate.cancel(previousLeaveAnimation);
202201
}
202+
203203
if(currentScope) {
204204
currentScope.$destroy();
205205
currentScope = null;
206206
}
207207
if(currentElement) {
208-
$animate.leave(currentElement).then(function() {
209-
previousElement = null;
208+
previousLeaveAnimation = $animate.leave(currentElement);
209+
previousLeaveAnimation.then(function() {
210+
previousLeaveAnimation = null;
210211
});
211-
previousElement = currentElement;
212212
currentElement = null;
213213
}
214214
}

‎test/ngRoute/directive/ngViewSpec.js

+3-13
Original file line numberDiff line numberDiff line change
@@ -845,18 +845,8 @@ describe('ngView animations', function() {
845845
});
846846
});
847847

848-
it('should destroy the previous leave animation if a new one takes place', function() {
849-
module(function($provide) {
850-
$provide.decorator('$animate', function($delegate, $$q) {
851-
var emptyPromise = $$q.defer().promise;
852-
$delegate.leave = function() {
853-
return emptyPromise;
854-
};
855-
return $delegate;
856-
});
857-
});
848+
it('should destroy the previous leave animation if a new one takes place',
858849
inject(function ($compile, $rootScope, $animate, $location) {
859-
var item;
860850
var $scope = $rootScope.$new();
861851
element = $compile(html(
862852
'<div>' +
@@ -884,8 +874,8 @@ describe('ngView animations', function() {
884874
$rootScope.$digest();
885875

886876
expect(destroyed).toBe(true);
887-
});
888-
});
877+
})
878+
);
889879
});
890880

891881

0 commit comments

Comments
 (0)
Please sign in to comment.