我正在为指令中的精灵设置动画,并且有一个scope.isAnimating
正在监视的范围变量。单击精灵时,值会反转并且动画停止/开始。第一次单击元素并更改值但不会第二次更改值时,手表会触发。
这不是完整的指令,而是一个缩写版本。如果您想实时看到这种情况发生,请单击精灵停止,然后再次单击它开始(不起作用)。
app.directive('sticker', function(timeFunctions){
return {
restrict: 'AE',
replace: true,
scope: {
isAnimated: '=isanimated',
Animation: '=animation',
speed: '=speed'
},
template: '<div></div>',
link: function(scope, element, attrs) {
scope.$watch('isAnimated', function(isAnimated) {
// fires on the first click but not the second, breakpoint not hit
if (scope.isAnimated) {
startAnimation();
} else {
timeFunctions.$clearInterval( scope.animateTimeout );
}
});
element.bind('click', function(e) {
e.preventDefault();
scope.isAnimated = !scope.isAnimated;
});
}
}
});
如何让手表在两次点击时都能正常工作?