title: Angular - create multiple directives from same function
body: <p>To create a directive/controller/factory whatever, you provide a function serving as the "injection point":</p>
  
  <pre><code>angular.module('myApp').directive('myDirective', ['dependencies', function injectionPoint(dependencies) {}]);
  </code></pre>
  
  <p>Can you provide that <code>injectionPoint</code> via another function registered with Angular?  e.g. a <code>factory</code>?  I should note that I've declared everything in separate files, and I'm trying to do it 'the angular way' and not create unnecessary globals.</p>
  
  <p>Specifically, I've got two input directives that are basically the same, just with different templates and isolate scope declaration.</p>
  
  <p>I thought to create a "directive factory" I could use, like:</p>
  
  <pre><code>function directiveFactory(scopeOverride, extraInit) {
      return function directiveInjectionPoint(depedencies) {
          return { restrict...,
                   template...,
                   scope: angular.extend({/*defaults*/}, scopeOverride),
                   link: function(...) {
                             // default stuff
                             if(angular.isDefined(extraInit)) extraInit($scope, el, attrs);
                         }
      }
  }
  </code></pre>
  
  <p>which I would then use like:</p>
  
  <pre><code>angular.module('myApp')
      .directive('myDirective1', directiveFactory({/* new stuff */))
      .directive('myDirective2', directiveFactory({/* other stuff */, fn2...));
  </code></pre>
  
  <p>But how do I register that function with Angular, and then use it in the directive declaration?</p>