我想使用角度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或任何东西存储上传的所有文件,该指令停止工作......
任何帮助都是适当的