title: AngularJS : Asynchronously initialize filter
body: <p>I'm having trouble trying to initialize a filter with asynchronous data.</p>
  
  <p>The filter is very simple, it needs to translate paths to name, but to do so it needs a correspondance array, which I need to fetch from the server.</p>
  
  <p>I could do things in the filter definition, before returning the function, but the asynchronous aspect prevents that</p>
  
  <pre><code>angular.module('angularApp').
    filter('pathToName', function(Service){
      // Do some things here
  
      return function(input){
        return input+'!'
      }
    }
  </code></pre>
  
  <p>Using a promise may be viable but I don't have any clear understanding on how angular loads filters.
  This <a href="https://stackoverflow.com/questions/16286605/initialize-angularjs-service-with-asynchronous-data">post</a> explains how to achieve such magic with services, but is it possible to do the same for filters?</p>
  
  <p>And if anyone has a better idea on how to translate those paths, I'm all ears.</p>
  
  <p>EDIT:</p>
  
  <p>I tried with the promise approch, but something isn't right, and I fail to see what:</p>
  
  <pre><code>angular.module('angularApp').filter('pathToName', function($q, Service){
  
    var deferred = $q.defer();
    var promise = deferred.promise;
  
    Service.getCorresp().then(function(success){
      deferred.resolve(success.data);
    }, function(error){
      deferred.reject();
    });
  
    return function(input){
      return promise.then(
        function(corresp){
          if(corresp.hasOwnProperty(input))
            return corresp[input];
          else
            return input;
        }
      )
    };
  });
  </code></pre>
  
  <p>I'm not really familliar with promises, is it the right way to use them?</p>