title: Make AngularJS service call async
body: <p>I have read about "promise" object and all the ways to get some sort of async call or wait until a http call is done, but I haven't been able to success. This is what I got and what I'm trying to do:</p>
  
  <p>I need to get some json file from my server and use the data from that json in my code (js file) and not only as data for my HTML template.</p>
  
  <p>I have a service that does the call to the json file:</p>
  
  <pre><code>mobilityApp.service('serveiWebservices', function($resource) {       
      return {        
          getWS: function($scope) {           
              var path = 'jsonWS/context.json';
              $resource(path).get(function (data) {                                                       
                  console.log(data); //data is printed fine
                  $scope.returnData = data; //just to test, it doesn't work neither
                  return data;            
              });
          }
      };    
  });
  </code></pre>
  
  <p>And from my controler I call it like this:</p>
  
  <pre><code>var data = serveiWebservices.getWS($scope);     
  console.log(data); //undefined
  </code></pre>
  
  <p>any idea on how to work with the promise object that the funcion returns and perform actions as soon as it gets the requested data ? i Know that I could set a "success" function but I would like not to use callbacks.</p>
  
  <p>Tnanks in advance ! </p>