title: Adding common code to an angular filter module
body: <p>I have 3 filters I need to write for a project, all 3 of them do the same thing, but with a different array from the $rootScope  (They are translating a numeric status into its display value).</p>
  
  <p>How can I write this code once and call it from all 3 filters AND keep that one instance inside the myFilters module?</p>
  
  <p>I'm not seeing a place I can put that code.  If I was writing a service, I'd have a block I could put it in, but with filters, I don't have that common spot to write the code.</p>
  
  <p>Right now I've just moved it to global scope, but I'd like to move it into the filter module so I don't have to repeat it 3 times, or store it on the global scope.</p>
  
  <pre><code>angular.module('myFilters', [])
  .filter('aStatus', function($rootScope) {
      return function(id, attr) {
          var objectArray = $rootScope.appConfig.aStatuses,
              index = _.findIndex(objectArray, function(obj) { return obj.id === id; });
          if(index &lt; 0) {
              return "";
          }
          if(attr) {
              return objectArray[index][attr];
          }
          return objectArray[index];
      };
  })
  .filter('bStatus', function($rootScope) {
      return function(id, attr) {
          var objectArray = $rootScope.appConfig.aStatuses,
              index = _.findIndex(objectArray, function(obj) { return obj.id === id; });
          if(index &lt; 0) {
              return "";
          }
          if(attr) {
              return objectArray[index][attr];
          }
          return objectArray[index];
      };
  })
  .filter('cStatus', function($rootScope) {
      return function(id, attr) {
          var objectArray = $rootScope.appConfig.cStatuses,
              index = _.findIndex(objectArray, function(obj) { return obj.id === id; });
          if(index &lt; 0) {
              return "";
          }
          if(attr) {
              return objectArray[index][attr];
          }
          return objectArray[index];
      };
  });
  </code></pre>