Support use of $animateProvider.classNameFilter(expr)
Hi All, thanks for your work on these components, we're really grateful to have them available!
By default, ng-animate tries to animate all of our ng-repeats which can cause performance degredation.
Would it be possible for material lib to include a class on all components that dep on ng-animate so that we could apply it more selectively with $animateProvider.classNameFilter()? See: https://docs.angularjs.org/api/ng/provider/$animateProvider
As is, one would need to explicitly blacklist elements from having ng-animate applied via $animate.enabled(false, element) calls.
Here is an example ng-animate lengthening our already slow digest cycle by close to 100ms:

Thanks @rschmukler, we are looking at using this solution for now, but what's painful about it is that it's a blacklist approach - we must remember to put it on every element we don't want animated.
A single class name we could use to whitelist animated components may be more convenient.
It sounds like this belongs in angular core instead of angular-material?
I misread. This is already implemented in angular, I see.
If you upgrade to the latest version of Angular while using Material then this should work.
Hi @ajoslin, sorry I didn't explain this well.
By default, ng-animate spends time in every digest cycle adding/removing classes on elements with ng-repeat directives. This is wasteful (see the profile screenshot above).
I was suggesting that material components relying on ng-animate be tagged with a marker class (maybe class="mt-animated") which would let our app call $animateProvider.classNameFilter(/mt-animated/) to tell ng-animate that it should only run on the marked directives/elements.
Since there is no marker class today, we disable animation individually for each component in our app that doesn't require it. So we've created a no-animate directive that disables animation on an element, and we're using throughout our app like this:
<div ng-repeat="thing in list" no-animate></div>
This works, but it would be nice if we had the option of using classNameFilter() instead.
@dguralnick - this sounds reasonable. I shifted the milestone for this one due to existing 0.9 and 0.10 efforts.
Following up from @jordan-thoms, here is some CoffeeScript to completely disable ng-animate unless they are angular material elements:
# Prevent ng-animate negatively affecting existing elements (e.g. ng-switch)
# by disabling animate unless it comes from ng-material elements (if element tag
# begins with "md" prefix)
ng.config ($provide) ->
$provide.decorator '$$animateQueue', ($delegate) ->
original = {
push: $delegate.push
}
$delegate.push = (element, event, options, domOperation) ->
node = (if element instanceof angular.element then element[0] else element)
element_name = node?.nodeName.toLowerCase()
# If element's tag does not begin with "md" for "material design"
# then don't use ng-animate
if element_name?.indexOf("md") isnt 0
if element instanceof angular.element
element.addClass 'ng-animate-disabled'
else
# NOTE: classList isn't supported in some browsers
element.classList.add 'ng-animate-disabled'
original.push arguments...
$delegate
return
ng.config ($animateProvider) ->
$animateProvider.classNameFilter /^(?:(?!ng-animate-disabled).)*$/
You can convert it to JS by using http://js2.coffee/
Super easy way. Use $animateProvider.classNameFilter to only allow ngAnimate to run on ngMaterial, and a classname of your own choosing. This assumes that everything that animates in ngMaterial has a classname that starts with md-. Been using it for a bit, seems to work as expected.
$animateProvider.classNameFilter(/(your-class-name|md-)/);