小编Mah*_*hen的帖子

使用angularjs上传多个文件

我想使用角度js上传多个文件,但它就像有限数量的文件,每个文件都有特定的验证,因此无法使用"多个".为每个文件使用多个控件一个..

下面是示例代码

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
  $scope.filelist = ['file1','file2']

});

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

corrposponding html是:

 <div ng-controller="MainCtrl">

      <div ng-repeat="myfile in filelist">
        <input type="file" file-bind="files" />
      </div>

      <div ng-repeat="file in files">
        <pre>{{ file | json }}</pre>
      </div>

    </div>
Run Code Online (Sandbox Code Playgroud)

我也为它做了一个东西:http://plnkr.co/edit/DF2WYU

但这不起作用...如果我使用$ index或任何东西存储上传的所有文件,该指令停止工作......

任何帮助都是适当的

javascript jquery file-upload angularjs

3
推荐指数
1
解决办法
3万
查看次数

标签 统计

angularjs ×1

file-upload ×1

javascript ×1

jquery ×1