title: AngularJS directive with method called from outside
body: <p>I created a directive with a method that should be called from other elements that are not part of the directive. However it looks like this method is not exposed. </p>
  
  <p><em>Some example jade code to clarify:</em></p>
  
  <pre><code>//- a controller for the view itself
  div(ng-controller="someController")
  
      //- this is part of the view itself, not within the directive
      div(ng-repeat="element in elements") 
          div(ng-click="methodFromDirective(element)") click element {{$index}} to trigger directive
  
      //- this is the directive
      div(some-directive)
  </code></pre>
  
  <p>The <code>someController</code> isn't too important here I think. It has methods but NOT the <code>methodFromDirective(element)</code> one. The <code>methodFromDirective(element)</code> is a method that exists only in the directive. </p>
  
  <p>If I make a directive and put some logging on creation I can clearly see it's created. However the <code>methodFromDirective(element)</code> method isn't exposed so the calls aren't properly triggered.</p>
  
  <p>The <code>methodFromDirective(element)</code> itself will only work on elements from within the directive's template.</p>
  
  <p><em>some coffeescript to show the definition of the the directive (ignore indentation errors here):</em></p>
  
  <pre><code>'use strict'
  define [], () -&gt;
  
  someDirective = () -&gt;
      restrict: 'A'
      scope: {
          show: '='
      }
      transclude: false
      templateUrl: 'someTemplateHere.html'
  
      controller = ($scope)  -&gt;
  
         # exposing the method here
         $scope.methodFromDirective(element)-&gt;
             $scope.theMethod element
  
      link = (scope, element, attr) -&gt;
  
         # this is logged
         console.log "init someDirective"
  
         # triggering this method form outside fails
         scope.theMethod = (element)-&gt;
            console.log "method triggered with element", JSON.stringify(element)
  </code></pre>