gpt4 book ai didi

javascript - 服务以 Angular 显示未定义

转载 作者:行者123 更新时间:2023-11-29 17:48:24 25 4
gpt4 key购买 nike

我写了一个服务,它将图像上传到服务器,我正在从 Controller 使用该服务,但在调用服务时显示服务中定义的未定义函数。错误是这样的“无法读取未定义的属性‘uploadFileToUrl’”

这是我的代码

app.service('fileUpload', ['$http', function ($http) {
this.uploadFileToUrl = function(file,clientid, uploadUrl){
var fd = new FormData();
fd.append('file', file);
fd.append('id', clientid);
$http.post(uploadUrl, fd, {
transformRequest: angular.identity,
headers: {'Content-Type': undefined}
})
.success(function(response){
console.log(response)
})
.error(function(){
});
}
}]);

我在这里调用此服务

app.controller('settingsCtrl', ['$scope','apiCall','$filter', function($scope,apiCall,$filter,fileUpload){
$scope.saveStudioBranch = function(){
studio();
admin();
branch();
}

function studio(){
var studio_json = {"session_id":session_id,"u":[{"col":"studio","val":$scope.studioDetails.studio},{"col":"type","val":$scope.studioDetails.type}],"filter":[["id","=","1"]],"table":"studio"};
apiCall.callEndpoint(studio_json,"settingRoute.php","update",json_header).then(function(response){
if(response.data.error == 0){
if($scope.inst_logo != undefined ){
var uploadUrl = "https://papa.fit/routes/registrationRoute.php?action=instLogo";
-->> fileUpload.uploadFileToUrl($scope.inst_logo,session.client_id,uploadUrl);
}
}
else
show_snack(response.data.message);
});

}
});

我在调用服务的地方添加了一个箭头

最佳答案

错误在注入(inject)

app.controller('settingsCtrl', ['$scope','apiCall','$filter', 
function($scope, apiCall, $filter, fileUpload){

你忘了在参数列表中添加fileUpload服务

app.controller('settingsCtrl', ['$scope','apiCall','$filter', 'fileUpload',
function($scope, apiCall, $filter, fileUpload){

关于javascript - 服务以 Angular 显示未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46661464/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com