angularjs exclude certain elements from animations

落花浮王杯 提交于 2019-12-25 03:01:48

问题


I'm using ngAnimate in some places but it's taking over animations for all my ng-class elements. I already had substantial animations code written for various elements that I don't need ngAnimate to take over. Their adding classes really seems to mess things up. Anyway to exclude those elements?

Here's the element I'm trying to exclude:

<div ng-class="myclass"></div>

ngAnimate adds classes like

$scope.myclass = 'move'

<div class="move-add" ng-class="myclass"></div>

回答1:


I was helped by jaawerth on IRC. He/she directed me to this link:

https://github.com/angular/angular.js/issues/5172

and advised me to write this directive:

.directive('noAnimate', ['$animate',
  function($animate) {
    return {
      restrict: 'A',
      link: function(scope, element, attrs) {
        $animate.enabled(false, element)
        scope.$watch(function () {
          $animate.enabled(false, element)
        })
      }
    };
  }
])

Which solved the problem.



来源:https://stackoverflow.com/questions/23879654/angularjs-exclude-certain-elements-from-animations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!