尝试找出使用 ng-file-upload 时能够删除文件的最佳方法。我得到了带有列表的文件列表。我的html是:
<div>
<p>Files:</p>
</div>
<div>
<ul>
<li ng-repeat="f in files" style="font:smaller">{{f.name}} {{f.$error}} {{f.$errorParam}}</li>
</ul>
</div>
在我的控制器中,我有:
$scope.$watch('files', function () {
$scope.upload($scope.files);
});
$scope.$watch('file', function () {
if ($scope.file != null) {
$scope.files = [$scope.file];
}
});
$scope.log = '';
$scope.upload = function (files) {
if (files && files.length) {
for (var i = 0; i < files.length; i++) {
var file = files[i];
if (!file.$error) {
Upload.upload({
url: (serviceBase + 'api/ppt/docs/upload/multi?transId=' + [$scope.transId]),
data: {
username: $scope.username,
file: file,
filename: file.name
}
}).progress(function (evt) {
var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
$scope.log = 'progress: ' + progressPercentage + '% ' +
evt.config.data.file.name + '\n' + $scope.log;
}).success(function (data, status, headers, config) {
$timeout(function() {
$scope.log = 'file: ' + config.data.file.name + ', Response: ' + JSON.stringify(data) + '\n' + $scope.log;
});
}).error(function(data, status, headers, config) {
var errors = [];
$scope.errors = data;
for (var i=0; i<$scope.errors.length; i++)
{
errors.push($scope.errors[i].errMsg);
}
$scope.message = "Error uploading files due to: " + errors.join(' ');
});
}
}
}
};
我在文档中看到了一些示例,但没有看到实现的最佳方法,特别是如果我希望为每个上传的文件而不是全部文件单独删除/删除。
非常感谢。