【发布时间】:2015-01-21 05:59:41
【问题描述】:
我正在尝试使用自定义指令“激活”来触发动画,我在这里将其用作属性,partials/test.html
<div activate="{{cardTapped}}" >
我在 js/app.js 中的应用定义之后定义指令
myApp.directive('activate', function ($animate) {
return function(scope, element, attrs) {
scope.$watch(attrs.activate,function(newValue){
console.log('fire');
if(newValue){
$animate.addClass(element, "full");
}
else{
$animate.removeClass(element, "full");
}
},true);
};
});
但是,$watch 仅在页面加载时触发。当cardTapped 更改值时,没有任何记录。我在这里尝试了几种参数变体无济于事,我已经看到了十几个类似的问题,但到目前为止我还没有找到解决方案
有什么想法吗?
【问题讨论】:
-
试试
attrs.$observe
标签: angularjs angularjs-directive watch