Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs angular文件上载未发布任何内容_Angularjs_Angular File Upload - Fatal编程技术网

Angularjs angular文件上载未发布任何内容

Angularjs angular文件上载未发布任何内容,angularjs,angular-file-upload,Angularjs,Angular File Upload,我正在尝试使用angular文件上传。文件正在从视图发送到角度控制器,但它没有向apiController发送任何内容。我犯了一个错误 它将文件放在 $scope.upload = function (files) { $scope.$watch('files', function () { $scope.upload($scope.files); }); $scope.upload = function (files) { if (files &&

我正在尝试使用angular文件上传。文件正在从视图发送到角度控制器,但它没有向apiController发送任何内容。我犯了一个错误

它将文件放在

$scope.upload = function (files) {
      $scope.$watch('files', function () {
    $scope.upload($scope.files);
});

$scope.upload = function (files) {
    if (files && files.length) {
        for (var i = 0; i < files.length; i++) {
            var file = files[i];
            $upload.upload({
                url: 'https://angular-file-upload-cors-srv.appspot.com/upload',
                fields: { 'companyName': $scope.companyName },
                file: file
            }).progress(function (evt) {
                var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
                console.log('progress: ' + progressPercentage + '% ' + evt.config.file.name);
            }).success(function (data, status, headers, config) {
                console.log('file ' + config.file.name + 'uploaded. Response: ' + data);
            });
        }
    }
};
$scope.upload=函数(文件){
$scope.$watch('files',function(){
$scope.upload($scope.files);
});
$scope.upload=函数(文件){
if(files&&files.length){
对于(var i=0;i
更新


我看到了你的成功函数是如何被击中的。我的仍然没有。而且我的控制台中没有javascript错误。我可以做些什么来调试它?

因为$scope.files是数组,所以你需要将$watch函数的第三个参数设置为“true”

   $scope.$watch('files', function () {
      console.log($scope.files);
        $scope.upload($scope.files);
    }, true);
请看这里的工作演示

app.controller('MainCtrl',函数($scope,$upload){
$scope.$watch('files',function()){
$scope.upload($scope.files);
});
$scope.upload=函数(文件){
if(files&&files.length){
对于(var i=0;i
我仍然得到与第三个参数相同的响应?进度:59%LovelaceWSH_CMYK.jpg 2app.js:19进度:100%LovelaceWSH_CMYK.jpg app.js:21文件LovelaceWSH_CMYK.jpguploaded.response:[对象]@texas697,你希望得到什么样的响应?请看这里哦,对不起,我搞糊涂了,我把你的代码添加到了我的plunker中。我知道你的代码是有效的,你在哪里添加的?它不在你的controller@texas697让我们看看这里,让我们看看。
app.controller('MainCtrl', function($scope, $upload) {
  $scope.$watch('files', function() {
    $scope.upload($scope.files);
  });

  $scope.upload = function(files) {
    if (files && files.length) {
      for (var i = 0; i < files.length; i++) {
        var file = files[i];
        $upload.upload({
          url: 'https://angular-file-upload-cors-srv.appspot.com/upload',
          fields: {
            'companyName': $scope.companyName
          },
          file: file
        }).progress(function(evt) {
          var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
          console.log('progress: ' + progressPercentage + '% ' + evt.config.file.name);
        }).success(function(data, status, headers, config) {
          console.log('file ' + config.file.name + 'uploaded. Response: ');
         //response from server          
         console.log(data);
        });
      }
    }
  };
});