title: calling controller function from link function
body: <p>I am trying to call a function in controller from link function. From controller function, I have to call a rest service call. (I tried calling rest service from link function , But I didn't get success. So I am trying to call controller function from link and from there I will call rest service).</p>
  
  <p>My code is as below.</p>
  
  <pre><code>app.directive('collection', function() {
      return {
          restrict: "E",
          replace: true,
          scope: {
              collection: '=',
              articleData: '=',
              articleContent: '='
          },
          template: "&lt;ul&gt;&lt;member ng-repeat='member in collection' member='member' article-data='articleData' article-content='articleContent'&gt;&lt;/member&gt;&lt;/ul&gt;"
      }
  });
  
  app.directive('member', function($compile,$http) {
      return {
          restrict: "A",
          replace: true,
          scope: {
              member: '=',
              articleData: '=',
              articleContent: '='
          },
          template: "&lt;div&gt;&lt;li&gt;&lt;a href='#' ng-click='getContent(member.itemId)'&gt;{{member.title}}&lt;/a&gt;&lt;/li&gt;&lt;/div&gt;",
          link: function(scope, element, attrs) {
              scope.getContent = function(itemId) {
  
                   scope.testFunction(itemId);
              }
  
              if (angular.isArray(scope.member.tocItem)) {
                  if (scope.member.hasChildren == "true") {
                      for (var i = 0; i &lt; scope.member.tocItem.length; i++) {
                          if (scope.member.tocItem.title) {
                              scope.member.tocItem.title.hide = true;
                          }
                      }
                  }
                  element.append("&lt;collection collection='member.tocItem'&gt;&lt;/collection&gt;");    
                  $compile(element.contents())(scope)
              }
          }
      }
  });
  
  app.controller('apdController', function($scope, getTocService,$location) {
      var bookId = $location.search().id;
      var sampdata = getTocService.getToc(bookId);
      $scope.tasks =sampdata;
      //$scope.tasks = data;
  
      var artData = getTocService.getArtData('PH1234');
      $scope.articleContent = artData;
  
      $scope.testFunction = function(itemId){
           alert("called.....");
          }
  });
  </code></pre>
  
  <p>Here, I am trying to call testFunction from link.From testFunction, I am planning to call a rest service. But getting undefined is not a function error. 
  Can someone please help? Also, please let me know is this a right approach (from link function to controller and from controller to rest call . Since my time line is less, I couldn't think of some other approach)</p>