У меня есть служба, которая загружает изображения из массива cloudinary.But, когда массив пуст, как я могу вернуть функцию без выполнения $ HTTP call.My код нижевозврат обещаний показывает ошибку в angularjs?
uploadPicture: function (files,title) {
if (!files)
promise = function(){}
return promise;
angular.forEach(files, function (file) {
if (file && !file.$error) {
promise = $upload.upload({
url: "https://api.cloudinary.com/v1_1/" + cloudinary.config().cloud_name + "/upload",
data: {
upload_preset: cloudinary.config().upload_preset,
tags: 'myphotoalbum',
context: 'photo=' + title,
file: file
}
}).progress(function (e) {})
.success(function (data, status, headers, config) {
return data;
}).error(function (data, status, headers, config) {
return data;
});
}
});
return promise;
}
}
Если файлы равна нулю, то это показывает ошибку
delregservice.uploadPicture(...).then is not a function
В моей controoler
$scope.Fn_SaveDeliveryAgent = function(){
delregservice.uploadPicture($scope.filelist[0],$scope.title).then(function(d){
$scope.delAgent.profile_pic = d;
}).then(function(){
delregservice.uploadPicture($scope.filelist[1],$scope.title).then(function(d){
$scope.delAgent.license_pic = d;
}).then(function(){
delregservice.saveDeliveryAgent($scope.delAgent).then(function(d){
console.log(d);
});
});
});
}
Как я могу решить эту проблему? Пожалуйста, помогите.Спасибо заранее и веселью X mas
я сделать это, дней назад, и я включил обновление в соответствии с новым обещанием. Загрузка не является обещанием. Может быть, это –