-
Notifications
You must be signed in to change notification settings - Fork 27.4k
$animate.cancel doesn't cancel add/removeClass animation #14204
Comments
Okay, there seem to be a few problems. For one, the docs are not really clear. What's returned from $animate.addClass et al is the animation runner, not the promise. The runner has a then fn that delegates to the internal promise. When you do
Hooowever, that still doesn't have the desired effect. I assume what you expect is that the animation stops and the final animation state is applied? |
Hi, thanks for getting back to me, I had been having some trouble with this elsewhere and extracted it out to a codePen and was surpised it didn't behave as described in the docs. I will change the then so it acts on the promise, but still the cancellation is annoying. I agree with you on the desired behaviour, As the cancel is on the animation it should end the transition applying the final state. |
Hi, I thought I'd add that I ran into this exact same issue (with |
Hi, checking the code (1.6.4) I see that cancel will call the runner.end(). However, I think it should actually call runner.cancel() instead. The cancel will call the reject of the promise, but end() calls the resolve. The intended semantics of the runner are a bit unclear (end() vs completed() vs cancel()). So, cancel is ending the animation after all, however not with a reject, but with a resolve of the promise. I now need to keep state myself to determine the reason for resolving. |
Hi @reitsma, since you brought this up again, would like to open a PR that changes this behavior and improves on the documentation? |
This has been the case since the "big ngAnimate refactor", but interestingly the initial implementation had a bug: cancel: function(runner) {
runner.cancel && runner.end();
} It is not clear whether the original intention was to use This was "fized" in a subsequent "documentation" change 😃 So, 👍 for fixing it, but sounds like a breaking change nonetheless. |
@reitsma you could open a PR which changes the cancel method to call runner.cancel, preferrably with tests included |
Closes angular#14204 BREAKING CHANGE: $animate.cancel(runner) now rejects the underlying promise and calls the catch() handler on the runner returned by $animate functions (enter, leave, move, addClass, removeClass, setClass, animate). Previously it would resolve the promise as if the animation had ended successfully. Example: ```js var runner = $animate.addClass('red'); runner.then(function() { console.log('success')}); runner.catch(function() { console.log('cancelled')}); runner.cancel(); ``` Pre-1.7.0, this logs 'success', 1.7.0 and later it logs 'cancelled'. To migrate, add a catch() handler to your animation runners.
Not sure this is the right place to report this, but I found very little on $animate.cancel on the issues or stackOverflow.
I have found the $animate.cancel does not seem to work with addClass and removeClass.
see codepen
http://codepen.io/johnjwood/pen/ZWWagW
The text was updated successfully, but these errors were encountered: