全局禁用 ng-animate,然后在某些元素上启用

Disable ng-animate globally and then enable on some elements

使用 Angular 1.5.3,是否可以全局禁用 ng-animate 然后在某些元素上选择性地启用它?

我有一个指令 (ng-animate-enabled) 用于在容器 div 及其子容器上启用 ng-animate。

如果我通过 $animate.enabled(false) 在控制器中全局禁用 ng-animate,即使我通过上述指令专门启用它们,动画也不再有效。

jsfiddle说明了问题。

谢谢!

最简单的方法是使用 $animateProvider.classNameFilter()。这使您可以根据 HTML class(或更具体地说,根据 class 检查的正则表达式)有选择地为某些元素启用 ngAnimate。这消除了启用 ngAnimate 的特定指令的需要,并且可以显着提升您的应用程序的性能。在你的情况下,我会这样做:

// Note that that the function takes a regular expression, not a string!
// Don't put quotes around it, use forward slashes!
$animateProvider.classNameFilter(/ng-animate-enabled/);

这将为具有 ng-animate-enabled class.

的任何元素启用 ngAnimate

有关更多信息,我建议阅读有关该主题的 Ben Nadel's blog post