-
Notifications
You must be signed in to change notification settings - Fork 27.4k
$animate.removeClass() doesn't work if addClass animation incomplete #7222
Comments
Working on a fix. |
This should be working now in master. Can you test it out using: https://code.angularjs.org/snapshot/ If not then this should be fully fixed when: #7767 goes in later today. |
This bug should now be fixed in master since #7767 is in. |
@greglockwood can you please retest this out on the |
This commit just did a huge fix on class based animations: You can test it out on the snapshot version: |
Not sure if related, but after upgrading from beta.19 to rc.0 I'm seeing issues with addClass not being applied with $animate. I have a spinner which shows/hides on http request using the following directive: .directive('loadingWidget', ['requestNotification', '$animate',
function (requestNotification, $animate) {
return {
restrict: 'AC',
link: function (scope, element) {
//subscribe to listen when a request starts
requestNotification.subscribeOnRequestStarted(function () {
// show the spinner!
$animate.removeClass(element, 'ng-hide');
});
requestNotification.subscribeOnRequestEnded(function () {
// hide the spinner if there are no more pending requests
if (requestNotification.getRequestCount() === 0) {
$animate.addClass(element, 'ng-hide');
}
});
}
};
}
])
|
With RC0 you need to run |
Thanks - looks like I should have read the commit notes! Using $timeout(function(){
$animate.addClass(element, 'ng-hide');
}); |
Don't use $timeout (since it also runs a digest). Do this: function safeApply(fn) {
$scope.$$phase ? fn() : $scope.$apply(fn);
}
safeApply(function() {
$animate.addClass(element, 'ng-hide');
}); |
I've tried using With |
OK. Would you mind creating a new issue and putting up a plunkr? I can have a look tomorrow. |
Request Type: bug
How to reproduce:
Component(s): ngAnimate, jqLite
Impact: medium
Complexity: small
Detailed Description:
The way I got this to occur was by using ng-class with the object syntax where the condition for one of the classes was initially true but then became false (possibly within the same $digest, I'm not sure). Hence the class was first added but then (unsuccessfully) removed.
I would imagine that the solution would be to check for active 'addClass' animations when trying to remove classes and if there is one for the class to be removed, cancelling it.
The text was updated successfully, but these errors were encountered: