title: $http post via an angularjs service
body: <p>I use the code below. The content of <code>dataService</code> is all the $http possible in my application. In the controller, I consume this function. The function call a Web Api service, this one is called and return the right response. In the function <code>customerToggleSuccess</code> the data is <code>undefined</code>. I don't understand why.</p>
  
  <pre><code>(function () {
      angular.module('myApp')
          .factory('dataService', ['$q', '$http']);
  
      function dataService($q, $http,) {
  
          return {
              customerToggleActive: customerToggleActive
          };
  
          function customerToggleActive(customerId, index) {
  
              var customer = {
                  "id": customerId,
                  "index": index
              };
  
              return $http({
                  method: 'POST',
                  url: 'api/customer/validtoggle/',
                  headers: {
                  },
                  transformResponse: function (data, headers) {
                  },
                  data: customer
              })
              .then(customerToggleData)
              .catch(customerToggleError)
          }
  
          function customerToggleData(response) {
              return response.data;
          }
  
          function customerToggleError(response) {
          }
      }
  
  }());
  
  (function () {
  
      angular.module('myApp')
          .controller('customerController', ['$scope', 'dataService', '$http', '$log', CustomerController]);
  
      function CustomerController($scope, dataService, $http, , $log) {
          var vm = this;
  
          vm.activeToggle = function (customerId, index) {
  
              dataService.customerToggleActive(customerId, index)
                  .then(customerToggleSuccess)
                  .catch(customerToggleCatch)
                  .finally(customerToggleComplete);
  
              function customerToggleSuccess(data) {
                  $log.info(data);
              }
  
              function customerToggleCatch(errorMsg) {
              }
  
              function customerToggleComplete() {
              }
  
          } 
  
      }
  
  }());
  </code></pre>