title: Angularjs: How to reference controller from within directive
body: <p>I have looked over many questions and blogs about "communicating between directives and controllers". Most of them really confuse me, and I cannot tell if they apply to me at all.</p>
  
  <p>I want:</p>
  
  <pre><code>   - to keep ng-controller in my html 
     - to avoid putting everything on $scope (ie. to use "controller as")
     - to prevent my controller from firing twice 
     - to send a method of a local-scope controller 
            to a method of another-scope controller.
  </code></pre>
  
  <p>I have gotten it to work <em>if I include a reference to the local-scope controller within the directive</em>. But then it forces that controller <strong>to be instantiated twice</strong>.</p>
  
  <p>So how to cleanly get a directive that is in the same local-scope as a controller to reference a method within that controller?</p>
  
  <p>SEE my <a href="http://plnkr.co/edit/dAXg3Dl2WdNMMNQA1mtA" rel="nofollow">plunker</a></p>
  
  <pre><code>&lt;head&gt;
    &lt;script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.min.js"&gt;
    &lt;/script&gt;
    &lt;script&gt;
      angular.module( "my_app" , [] )
        .controller( "A_controller" , 
                     function( $scope )
                       { $scope.A_method = function( argf )  
                                             { argf.apply( null) ;      
                                             } ;
                      }
                    )
        .controller( "B_controller" , 
                     function( $scope )
                       { console.log( "B initiated" ) ; 
                         // FIRES TWICE if directive includes 'controller:"B_controller"'
  
                         var B_this = this ;     
  
                         //$scope.B_method = function() { alert( "GOAL" ) ;  } ; 
                           B_this.B_method = function() { alert( "GOAL" ) ;  } ; 
                       } 
                   )
        .directive( "bDirective" , 
                    function()
                       { return {
                                  controller : "B_controller" ,
                                  link : function( scope , element , atts , ctrl )  
                                           {
                                             //scope.A_method( scope.B_method ) ; 
                                             //    SUCCEEDs,
                                             //      ... if B_method is on $scope
                                             //      ... but I understand that  
                                             //      ... 'controller as ...' is better
  
                                             scope.A_method( ctrl.B_method  ) ; 
                                             //     SUCCEEDS, 
                                             //       ... if I include 
                                             //       ... 'controller:"B_controller"'  
                                             //       ... but that fires the 
                                             //       ... "B_controller" twice
                                           }
                                } 
                       }
                   )
    &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body ng-app        = "my_app"
        ng-controller = "A_controller" &gt;
  
    &lt;div ng-controller = "B_controller as B_this"&gt;
      &lt;div b-directive&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  
  &lt;/body&gt;
  </code></pre>