title: Angular ngStyle Variable Style
body: <p>I am trying to give my div dynamic style - I want the css to come from the controller , where the css object the controller returns isn't hard-coded but changes dynamically(I need a 'top' field which is a variable). I am using ng-style to try to achieve this :</p>
  
  <pre><code>-html- 
  &lt;div id="preview" ng-style="setTopPosition()"&gt;
  
   -controller- 
      $scope.setTopPosition = function() {
      console.log("top position: "  +  $scope.topPosition);
     var retObj =  { top : $scope.topPosition , background: "green" };
      console.log(retObj);
      return retObj
  };
  </code></pre>
  
  <p>Now I know that the values I'm expecting ($scope.topPosition etc) are there(they show in console log) , and I know the controller is running it's code since the div's background turns green . However , the top position part is not working . Can't ng-style use objects with variable fields ? Also , does this need to be in a custom directive instead ?</p>