title: $http return response - AngularJS
body: <p>I need to create service in AngularJS to return the response of HTTP requests. My problem is the asynchronous request, because after I've submitted the request, my function returns <code>undefined</code> instantly and does not return the response from the server.</p>
  
  <pre><code>app.service('TesteService', function($http) {    
  
      this.teste = function(data) {
          var data = "*";
  
          $http({
              method: 'GET',
              url: 'teste-s.php',
              params: {data: "bem recebido"}
          }).then(function successCallback(response) {
              data = response.data;
              alert(data);
              return data;
          }, function errorCallback(response) {
              data = "500";
          });
      }
  });
  </code></pre>
  
  <p>How do I fix this?</p>