无法在 angular 工厂内使用 $http (angular 1.x)

Cannot use $http within angular factory (angular 1.x)

我在脚本的开头添加了 $http 但由于某些原因未加载 $http - 如何将 $http 登录到模块而不是控制器

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); 
        }
    );
   }

}
}]);

//控制台日志错误

$http is not defined...

您只需在工厂的依赖项注入中包含 $http,然后将 $scope.http 切换为 $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); 
        }
    );
   }

}
}]);