AngularJs FTP多个文件

AngularJs FTP multiple files

本文关键字:文件 FTP AngularJs      更新时间:2023-09-26

我正在尝试使用angular js上传多个文件,但值没有存储在模型文件存储

Htmlcode:

 <div ng-app="myApp">
   <div ng-repeat="file in filelist">
          <label>{{file.name}} </label> 
          <input type="file" ng-model="filestore[$index]" />
   </div>  
</div>
<div>
     <input type="button" value="submit" ng-click="savefiles(filestore)"/>
</div>

js:

 myApp.controller('uploadCtrl', function ($scope,$http) {
 //list of file names
 $scope.filelist = ["file1", "file2", "file3"];
 //save file list
 $scope.savefilelist = function(filestore) {
    $http({
        method: 'POST',
        url: '/api/SaveFiles',
        data: filestore
    });
 };

})

http://plnkr.co/edit/7b0G59z0ExglBane87um?p =

预览

下面是你如何通过自定义指令来实现的例子。

app.directive("fileBind", function() {
  return function( scope, elm, attrs ) {
    elm.bind("change", function( evt ) {
      scope.$apply(function() {
        scope[ attrs.fileBind ] = evt.target.files;
      });
    });
  };
});

如果您需要使用ng-repeat,这里是替代解决方案。

http://plnkr.co/edit/aJAmbo?p =

预览
  1. 如果在ng-repeat循环中使用binding,则使用object。
  2. 在指令中使用绑定,这样可以很容易地实现复杂的引用。