title: Which parameters to pass into Angular JS custom directive controller?
body: <p>I'm trying to create a custom directive which needs to use a separate controller because it needs to have functions which can be called by child directives.</p>
  
  <p>Here is my code so far:</p>
  
  <pre><code>angular.module('myDirectives').controller('SlideInMenuController', function ($scope, $element, $attrs) {
  
      $scope.isOpen = false;
  
      // Toggle Function
      this.toggle = function(){
  
          $scope.$apply(function(){
              $scope.isOpen = !$scope.isOpen;
          });
  
      };
  
  
      // Watch $scope.isOpen and open the menu
      $scope.$watch('isOpen', function() {
  
          if($scope.isOpen == true){
              $element.attr('is-open', true);
          }
          else{
              $element.attr('is-open', false);
          }
  
          return false;
  
      });
  
  }
  
  angular.module('myDirectives').directive('slideInMenu', function ($swipe) {
  
      return {
  
          restrict: 'EA',
          scope: {},
          controller:'SlideInMenuController'        
  
      };
  
  });
  
  
  angular.module('myDirectives').directive('slideInMenuToggle', function ($swipe) {
  
      return {
  
          restrict: 'EA',
          require: '^slideInMenu',
  
          link: function ($scope, $element, $attrs, SlideInMenuCtrl) {
  
              $element.bind('click', function(){
                  SlideInMenuCtrl.toggle();
              });
  
          }        
  
      };
  
  });
  </code></pre>
  
  <p>(Note: I'm using ng-annotate so I don't have to write all my dependencies twice)</p>
  
  <p>I need to inject the $swipe service into the directive controller but a normal controller would't have $scope, $element, $attrs as the first three parameters. This has made me wonder if I should be putting those into the link function instead and doing DOM stuff there, but if I do that what goes in the controller and what goes in to the link function.</p>
  
  <p>I've read numerous blogs and SO answers that say what order compile/link/controller are run in but still can't find a clear answer as to whatin my above example should go where.</p>
  
  <p>Any help would really be appreciated.</p>