title: AngularJS : Passing a function to an isolated scope of a directive to be called within its controller?
body: <p>I'm trying to call a function passed from a controller's scope into a directive via the "&amp;" operation from the directive's controller. That method, however, is claimed by Angular to be undefined. After reading my code over and over, scouring the internet, and then repeating that process, I've decided to turn to help here. </p>
  
  <p>Here's the relevant part of my controller. It contains the method I pass to my directive.</p>
  
  <pre><code>angular.module('myApp.controllers', []).controller('PostCtrl', ['$scope', 'postalService', function($scope, postalService) {
      $scope.posts = [];
  
      $scope.getPosts = function() {
          postalService.getPosts(function(err, posts) {
              if(err);
              else $scope.posts = posts;
          });
      };
  }]);
  </code></pre>
  
  <p>Here's my directive. I am unable to invoke onPost. </p>
  
  <pre><code>angular.module('myApp.directives', []).directive('compose', ['postalService', function(postalService) {
      return {
          restrict: 'E',
          transclude: false,
          replace: true,
          scope: {
              onPost: "&amp;" //why will it not
          },
          templateUrl: "partials/components/compose-partial.html",
          controller: function($scope, postalService) {
              $scope.title = "";
              $scope.content = "";
              $scope.newPost = function() {
                  postalService.newPost($scope.title, $scope.content, function(err) {
                      if(err) console.log(err + ":(");
                      else {
                          console.log("Success getting posts.");
                          //why can I not invoke onPost()??
                          $scope.onPost();
                      }
                  });
              };
          },
      };
  }]);
  </code></pre>
  
  <p>And here's the relevant part of my html</p>
  
  <pre><code>&lt;div ng-controller="PostCtrl"&gt;
      &lt;section class="side-bar panel hide-for-small"&gt;
          &lt;compose onPost="getPosts()"&gt;&lt;/compose&gt;
      &lt;/section&gt;
  
      &lt;!--more, non-relevant html here--&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>I know the problem is not with my postalService Service. Instead, the directive reports that no function is passed to it. Why??</p>