繁体   English   中英

将文件提交到ng-file-upload时文件未定义

[英]Files are undefined when submitting files to ng-file-upload

我有以下问题:

我正在使用ng-file-upload将文件发布到后端。 我已经将放置区域设置为当有人按下a按钮时通过ng-if显示。 这可以完美工作,我可以选择一个文件,并且也可以在ng-file-upload演示中看到它的名称。 用户现在应该可以在单击“保存”时上载此文件,但是每次执行此操作时,角度都会告诉我该文件未定义。

这里是我的上传和保存方法:

上载:

  $scope.upload = function (files) {
        console.log($scope.files);
    if ($scope.files && files.length) {
        for (var i = 0; i < files.length; i++) {
            var file = files[i];
            $upload.upload({
                url: base+'/doc/'+$scope.project_id+'?name='+$scope.doc.name,
                                    method: 'POST',
                doc: 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: ' +
                            JSON.stringify(data));
            });
        }
    }
};

救:

$scope.saveDoc = function(){
    console.log($scope.files);
}

我想不出为什么文件应该为空的原因,因为前端中的ng-repeat起作用了。

<div ng-file-drop ng-file-select ng-model="files" class="drop-box"
      drag-over-class="dragover" ng-multiple="true" allow-dir="true">Drop pdfs or images here or click to upload</div>
  <div ng-no-file-drop>File Drag/Drop is not supported for this browser</div>
  <ul>
    <li ng-repeat="f in files" style="font:smaller">{{f.name}}</li>

它完美地显示了我的名字。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM