我在脚本开头添加了$ 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...
答案 0 :(得分:3)
您只需在工厂的依赖注入中加入$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);
}
);
}
}
}]);