Here I am getting one issue while uploading multiple images on AngularJS. Here is my code and the error I'm getting.
$scope.saveFile = function(file) {
return Upload.upload({
url: CONFIG.apiUrl + '/fileupload',
data: {
fileUpload: file
}
}).success(function(data) {
console.log("RSPPPPPPP", data.file._id);
$scope.photoId = data.file._id;
console.log("sdvfbghjm,kjhgfdsa", $scope.photoId);
})
return $scope.saveFile;
//}
};
$scope.Addprojects = function(prodetails) {
if (prodetails.image1_id) {
$scope.prodetails.file.push(prodetails.image1_id);
//console.log("image1", prodetails.file);
}
if (prodetails.image2_id) {
$scope.prodetails.file.push(prodetails.image2_id);
//console.log("image2", prodetails.file);
}
//console.log(prodetails.file.length);
if (prodetails.file.length == 2) {
alert(prodetails.file.length);
$scope.saveFile(prodetails.file[0]).then(function(res) {
console.log("poooototot", res);
$scope.saveFile(prodetails.file[1]).then(function(res) {
$scope.Addprojectsimg(prodetails);
console.log("", Addprojectsimg);
alert('hai');
});
});
} else if (prodetails.file.length == 1) {
$scope.saveFile(prodetails.file[0]).then(function(res) {
alert("ok");
$scope.Addprojectsimg(prodetails);
});
} else {
$scope.Addprojectsimg(prodetails);
}
};
$scope.Addprojectsimg = function(prodetails){
console.log("projectadding",prodetails,$scope.photoId);
prodetails.image1_id= $scope.photoId;
console.log("SUB",prodetails);
$http.post(CONFIG.apiUrl+"/projectsubmit", prodetails).success(function(data, status) {
console.log("prorespons",data);
alert("images uploaded sucessfully");
})
};
Error
Error: $scope.saveFile(...).then is not a function addprojectctrl/$scope.Addprojects@http://192.168.3.40:8081/2016/ANGULAR2016/ang-social/js/controllers.js:208:7 anonymous/fn@http://192.168.3.40:8081/2016/ANGULAR2016/ang-social/bower_components/angular/angular.js line 13365 > Function:2:332 ngEventHandler/http://192.168.3.40:8081/2016/ANGULAR2016/ang-social/bower_components/angular/angular.js:23613:17 $RootScopeProvider/this.$gethttp://192.168.3.40:8081/2016/ANGULAR2016/ang-social/bower_components/angular/angular.js:16052:16 $RootScopeProvider/this.$gethttp://192.168.3.40:8081/2016/ANGULAR2016/ang-social/bower_components/angular/angular.js:16152:20 ngEventHandler/<@http://192.168.3.40:8081/2016/ANGULAR2016/ang-social/bower_components/angular/angular.js:23618:17 n.event.dispatch@http://192.168.3.40:8081/2016/ANGULAR2016/ang-social/bower_components/jquery/dist/jquery.min.js:3:7467 n.event.add/r.handle@http://192.168.3.40:8081/2016/ANGULAR2016/ang-social/bower_components/jquery/dist/jquery.min.js:3:5583 return logFn.apply(console, args);
Please guide me to fix this issue. I think it small error only but i am new to AngularJS.