title: AngularJS: Get $http response from function in module
body: <p>how do i get the response from $http in from a function in a module?</p>
  
  <p>Angular module:</p>
  
  <pre><code>// module customServices
  var customServices = angular.module("customServices", []);
  
  // object for response
  httpResponse = {content:null};
  
  // function sendRequest
  function sendRequest(param)
  {
    // inject $http
    var initInjector = angular.injector(['ng']);
    var $http = initInjector.get('$http');
  
    // set header
    $http.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
  
    $http({
      // config
      method: 'POST',
      url: 'response.php',
      data: $.param(param),
  
      // success
      }).success(function (response, status, headers, config) {
        httpResponse.content = response;
  
      // error
      }).error(function (response, status, headers, config) {
        console.warn("error");
  
      });
  }
  
  // factory - moduleService
  customServices.factory("moduleService", function () {
  
    return {
  
      // function - members
      members: function(param)
      {
        switch(param.fc)
        {
          // getAll
          case 'getAll':  
            sendRequest({
              service :'members',
              fc      : param.fc,
              id      : param.id
          });
          return httpResponse;
        }
  
      },
  
    };
  
  });
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>myApp.controller('main', ['$scope', '$http', 'moduleService', function($scope, $http, moduleService){
  
    $scope.handleClick = function () {
  
      var ReturnValue = moduleService.members({
        fc:'getAll',
        id:'123',
      });
  
      console.log(ReturnValue);
  
    };
  
  }]);
  </code></pre>
  
  <p>the object is on the first click empty and on the second click its content is the $http response.</p>
  
  <p>but i want that the controller knows when the $http response is available.</p>
  
  <p>i tried to use $broadcast and $on, but it seems to be impossible to use $rootScope in my function "sendRequest".</p>