title: AngularJS directives attributes access from the controller
body: <p>I am trying to access the attributes of a directive in the controller function. However, by the time I access it, it is undefined. I noticed that if I do a simple timer it works. Is there a way to execute code only after the directive and it's scopes are ready and set to be used?</p>
  
  <p>I made a fiddle with it. Make sure your console is open. <a href="http://jsfiddle.net/paulocoelho/uKA2L/1/">http://jsfiddle.net/paulocoelho/uKA2L/1/</a></p>
  
  <p>Here is the code I am using in the fiddle:</p>
  
  <pre><code>&lt;div ng-app="testApp" &gt;
      &lt;testcomponent text="hello!"&gt;&lt;/testcomponent&gt;
  &lt;/div&gt;
  </code></pre>
  
  
  
  <pre><code>var module = angular.module('testApp', [])
      .directive('testcomponent', function () {
      return {
          restrict: 'E',
          template: '&lt;div&gt;&lt;p&gt;{{text}} This will run fine! &lt;/p&gt;&lt;/div&gt;',
          scope: {
              text: '@text'
          },
          controller: function ($scope, $element) {
              console.log($scope.text); // this will return undefined
              setTimeout(function () {
                  console.log($scope.text);    // this will return the actual value...
              }, 1000);
          },
          link: function ($scope, $element, $attrs) {
              console.log($scope.text);
              setTimeout(function () {
                  console.log($scope.text);
              }, 1000);
          }
      };
  });
  </code></pre>