Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access to the current element with ng-style

Tags:

angularjs

I'd like to get access to the current element css properties when I use ng-style

Since the following element:

<div ng-style="changeWidth()">

Get access to its CSS properties

$scope.changeWidth = function(element) {
    return {
       width: element.width() / 2
    }
};

Someone knows the best way to achieve that?

like image 352
Lt. Avatar asked Oct 07 '13 11:10

Lt.


1 Answers

Use directives:

.directive("getStyle",function(){
  return{
    link:function(scope,element){
      element[0].style.border = "5px dotted #090";
    }        
  }      
});

Example: http://plnkr.co/edit/izOrEi?p=preview

One more (directive-scope interaction): http://plnkr.co/edit/uL7N1j?p=preview

like image 95
Ivan Chernykh Avatar answered Oct 18 '22 21:10

Ivan Chernykh