angularjs 中的多张图片上传错误

Multiple Image uploading error in angularjs

我在 AngularJS 上上传多张图片时遇到一个问题。这是我的代码和我遇到的错误。

$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: $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);

请指导我解决这个问题。我认为这只是一个小错误,但我是 AngularJS.

的新手

您的 $scope.saveFile 函数没有返回承诺,它应该是这样的:

$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);

    });
};