不调用angularjs指令

时间:2016-03-23 06:23:54

标签: angularjs animate.css

我正在尝试在范围值更改上应用动画类,但是指令永远不会在此处调用。

    <md-card animateOnChange="currentCard.fab_id">
    <md-card-header-text>
      <span class="md-subhead">Id: {{currentCard.fab_id}} </span>
    </md-card-header-text>
  </md-card-header>
</md-card>

指令:

.directive('animateOnChange', function($timeout) {
   return function(scope, element, attr) {
        scope.$watch(attr.animateOnChange, function(nv,ov) {
            if (nv!=ov) {
                element.addClass('animated shake changed');
                $timeout(function() {
                    element.removeClass('animated shake changed');
                }, 1000);
            }
        });
    }
  })

1 个答案:

答案 0 :(得分:0)

尝试:

<md-card animate-on-change="currentCard.fab_id">

scope.$watch(attr.animateOnChange, function(nv,ov) {...}

因为angularjs规范化了指令和属性。见https://docs.angularjs.org/guide/directive