使用 Angular 1.5.3,是否可以全局禁用 ng-animate,然后有选择地在某些元素上启用它?
我有一个指令 (ng-animate-enabled
),用于在容器 div
及其子容器上启用 ng-animate。
如果我通过 $animate.enabled(false)
在 Controller 中全局禁用 ng-animate,即使我通过上述指令专门启用它们,动画也不再起作用。
这个jsfiddle说明了问题。
谢谢!
最佳答案
最简单的方法是使用 $animateProvider.classNameFilter()
。这使您可以根据 HTML 类(或更具体地说,根据该类检查的正则表达式)选择性地为某些元素启用 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
类的元素启用 ngAnimate。
有关更多信息,我建议阅读 Ben Nadel's blog post就主题而言。
关于angularjs - 全局禁用 ng-animate,然后在某些元素上启用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37397940/