In my AngularJS application I'm using fontawesome for my loading spinners:
<i class="fa fa-spin fa-spinner" ng-show="loading"></i>
I'm also using AngularToaster for notification messages which has a dependency on ngAnimate. When I include ngAnimate in my AngularJS application, it messes up my loading spinners by animating them in a weird way. I want to stop this from happening but cant find a way to disable the animation on just these loaders (it would also stink to have to update every loader I have in my app).
Heres a plunkr showing my exact problem.
I think the best way to do this is to use the
$animateProvider.classNameFilter
which will allow you to filter items to animate or in this case not to animate. We'll do something like:Demo:
http://plnkr.co/edit/lbqviQ87MQoZWeXplax1?p=preview
Angular docs state:
As another answer per the comment with the
no-animate
directive, you could write anng-show
directive that will run at a higher priority and disable the animation. We will only do this if the element has thefa-spinner
class.Demo: http://plnkr.co/edit/BYrhEompZAF5RKxU7ifJ?p=preview
Lastly, and similar to the above, we can use the
no-animate
directive if we want to make it a little more modular. In this case I'm naming the directivefaSpin
which you could do in the answer above. This is essentially the same only we are preserving the directive from the SO answer mentioned in the comment of the above codeset. If you only care about thefa-spin
animation issues naming it this way works well, but if you have otherng-show
animation problems you'd want to name itngShow
and add to the if clause.Demo: http://plnkr.co/edit/P3R74mUR27QUyxMFcyf4?p=preview
I had a similar problem where my icon would keep spinning until the animation finished, even after the $scope variable turned off. What worked for me was to wrap the
<i>
fa-icon element in a span.Try it!
I've found an easier way.
Forked plunker: http://plnkr.co/edit/mCsw5wBL1bsLYB7dCtQF
I did run into another small issue as a result of doing this where the icon would appear out of position if it spun for more than 2 seconds, but that was caused by the 'ng-hide-add-active' class, so I just added in my css:
and that took care of it.
EDIT: Nico's solution is a slightly cleaner version of this, so I'd consider using his.
Then you can just add the class
ng-animate-disabled
to any element you want.<button><i class="fa fa-spinner ng-animate-disabled" ng-show="somethingTrue"></i></button>
Updating James Fiala Answer.
You don't need the
ng-class
as mentioned in @James Fiala Answer. But you should havefa-spin
as one of the class.Add style