我已經編寫了一個將圖像上傳到服務器的服務,我正在使用來自控制器的服務,但是調用服務時顯示服務中定義的未定義函數。和錯誤是這樣的「的未定義無法讀取屬性 '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);
});
}
});
我添加了一個箭頭,我打電話給服務
顯示代碼你在哪裏注入服務 – Satpal
ohh對不起。我會編輯上面的代碼,並請重新檢查它 –