我想在使用 ng-style 时访问当前元素的 css 属性
由于以下元素:
<div ng-style="changeWidth()">
访问其 CSS 属性
$scope.changeWidth = function(element) {
return {
width: element.width() / 2
}
};
有人知道实现这一目标的最佳方法吗?
最佳答案
使用指令:
.directive("getStyle",function(){
return{
link:function(scope,element){
element[0].style.border = "5px dotted #090";
}
}
});
示例:http://plnkr.co/edit/izOrEi?p=preview
再一个(指令范围交互):http://plnkr.co/edit/uL7N1j?p=preview
关于angularjs - 如何使用 ng-style 访问当前元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19223723/