你好,我有一张图片需要旋转。页面上有两个按钮,左右分别按下可以使图片向相反方向旋转45度。我尝试使用jQuery的旋转库创建了一个指令,但是它没有起作用。能否给予帮助?
directive.js
.directive('rotate', function() {
return {
restrict:'A',
link: function(scope, element, attrs) {
console.log('hi');
// watch the degrees attribute, and update the UI when it changes
scope.$watch(attrs.degrees, function(rotateDegrees) {
console.log(rotateDegrees);
//transform the css to rotate based on the new rotateDegrees
element.rotate(rotateDegrees);
});
}
}
});
template.html
<p><img degrees='angle' rotate id='image' src='myimage.jpg'/> </p>
<a ng-click="rotate('-45')">Rotate Left</a>
<a ng-click="rotate('45')">Rotate Right</a>
controller.js
$scope.rotate= function(angle) {
$scope.angle=angle;
};