title: how to make sure that my js run after directive loaded in angularjs
body: <p>I have a directive which renders a view template and some js code in my main page which tries to get some element in my view template. And since the js code is executed before the template rendered, the will always be undefined error like</p>
  
  <pre><code>&lt;body ng-app="myApp"&gt;
  &lt;test&gt;&lt;/test&gt;
  &lt;script src="angular.js"&gt;&lt;/script&gt;
  &lt;script src="directives.js"&gt;&lt;/script&gt;
  &lt;script&gt;
      //try to get an element in directive and failed
      alert(document.getElementById('testdiv').innerHTML);
  &lt;/script&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>simple in directive.js</p>
  
  <pre><code>angular.module('myApp', []).directive('test', function(){
    return {
        restrict: 'E',
        template: '&lt;div id="testdiv"&gt;Hello&lt;/div&gt;'
    }
  });
  </code></pre>
  
  <p>I am not very familiar with angular and your help will be appreciated. Thanks </p>