-1

I have added $http at the start of the script but for some reason the $http isn't loaded - how do I log $http into the module rather than the controller

var abcdReportServices = angular.module('abcdReportServices', [ ]);

abcdReportServices.factory('uploadFileAjax', ['getPDFsImage', function(getPDFsImage) {
   return function(evt, $scope){
           $scope.http({
              method: "POST",
              url: 'someEndpoint/doSomething',
               data: $.param({
                 'name': 'name-of-rpt'
            }),
        headers: {
            "Content-Type" : "application/x-www-form-urlencoded"
        }
    }).success(
        function(data) {
            console.log("Saving success", data); 
        }
    );
   }

}
}]);

// error in console log

$http is not defined...
Zabs
  • 13,852
  • 45
  • 173
  • 297

1 Answers1

3

You just need to include $http in your factory's dependency injection and then switch your $scope.http to $http.

var abcdReportServices = angular.module('abcdReportServices', [ ]);

abcdReportServices.factory('uploadFileAjax', ['getPDFsImage', '$http', function(getPDFsImage, $http) {
   return function(evt){
           $http({
              method: "POST",
              url: 'someEndpoint/doSomething',
               data: $.param({
                 'name': 'name-of-rpt'
            }),
        headers: {
            "Content-Type" : "application/x-www-form-urlencoded"
        }
    }).success(
        function(data) {
            console.log("Saving success", data); 
        }
    );
   }

}
}]);
Tyler
  • 1,029
  • 1
  • 8
  • 20