title: AngularJS DOM Access On Init
body: <p>I wrote this simple jsfiddle in which I do (successfully) some basic addClass on a directive in a ng-repeat.</p>
  
  <p><a href="http://jsfiddle.net/rv6u2/5/" rel="nofollow noreferrer">http://jsfiddle.net/rv6u2/5/</a></p>
  
  <p>Now, my question is: which is the best (<i>or intended</i>) place to do such DOM manipulations:</p>
  
  <p><strong>A. In the directive?</strong></p>
  
  <p><strong>B. In the controller?</strong></p>
  
  <p>Both possibilities are shown in my example.</p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>var TestApp = angular.module("TestApp", ['ngResource']);
  TestApp.directive('onLoad', function() {
      return {
          restrict: 'A',
          link: function(scope, elm, attrs) {
              elm.addClass('loaded'); // A: DOM manipulation in directive
              scope.initMe(scope.$eval(attrs.onLoad2), elm); // B: DOM manipulation handled in controller
          }
      };
  });
  </code></pre>
  
  <p>thanks in advance :)</p>