diff options
| author | Matias Niemelä | 2014-02-21 03:43:50 -0500 |
|---|---|---|
| committer | Matias Niemelä | 2014-02-26 14:53:57 -0500 |
| commit | e9881991ca0a5019d3a4215477738ed247898ba0 (patch) | |
| tree | 5bca5a431522715543288b94772882dcd994bbe2 /src/ng/directive/ngSwitch.js | |
| parent | c9245cf759108add2a10ffca4d41b1c68c1e8c76 (diff) | |
| download | angular.js-e9881991ca0a5019d3a4215477738ed247898ba0.tar.bz2 | |
fix($animate): ensure that animateable directives cancel expired leave animations
If enter -> leave -> enter -> leave occurs then the first leave animation will
animate alongside the second. This causes the very first DOM node (the view in ngView
for example) to animate at the same time as the most recent DOM node which ends
up being an undesired effect. This fix takes care of this issue.
Closes #5886
Diffstat (limited to 'src/ng/directive/ngSwitch.js')
| -rw-r--r-- | src/ng/directive/ngSwitch.js | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/ng/directive/ngSwitch.js b/src/ng/directive/ngSwitch.js index 92594978..378c0b50 100644 --- a/src/ng/directive/ngSwitch.js +++ b/src/ng/directive/ngSwitch.js @@ -138,12 +138,31 @@ var ngSwitchDirective = ['$animate', function($animate) { var watchExpr = attr.ngSwitch || attr.on, selectedTranscludes, selectedElements, + previousElements, selectedScopes = []; scope.$watch(watchExpr, function ngSwitchWatchAction(value) { - for (var i= 0, ii=selectedScopes.length; i<ii; i++) { - selectedScopes[i].$destroy(); - $animate.leave(selectedElements[i]); + var i, ii = selectedScopes.length; + if(ii > 0) { + if(previousElements) { + for (i = 0; i < ii; i++) { + previousElements[i].remove(); + } + previousElements = null; + } + + previousElements = []; + for (i= 0; i<ii; i++) { + var selected = selectedElements[i]; + selectedScopes[i].$destroy(); + previousElements[i] = selected; + $animate.leave(selected, function() { + previousElements.splice(i, 1); + if(previousElements.length === 0) { + previousElements = null; + } + }); + } } selectedElements = []; |
