title: How can I call link directive function after controller code has been run
body: <p>I'm trying to render code in the link function after the controller resolves the http call but the link function is called before that. How can I call link after <code>$scope.menuHtml</code> has been set?</p>
  
  <p><strong>HTML:</strong></p>
  
  <pre><code>  &lt;div id="testD" nav-menu-output="parseMenuJsonAndOutPutMenu()"&gt;&lt;/div&gt;
  </code></pre>
  
  <p><strong>DIRECTIVE:</strong></p>
  
  <pre><code>return {
      restrict: 'A',
      controller: ['$scope', '$q','$http', function ($scope, $q,$http) {
          $http.get('ajax/menu' ).then(function (data) {
              $scope.menuHtml = generateHtmlMenu(data);
          });
      }],
      link: function(scope, element, attr) {
          var templateString = scope.menuHtml;
          var compiledTemplate = $compile(templateString)(scope);
          compiledTemplate.appendTo("#testD");
      }
  
  }
  </code></pre>