在这里,我使用Daniel Farid的精彩ng-file-upload,并遵循multiple files one by one on file select方法(以解决我在此处遇到的一些兼容性问题/要求):
app.controller('MyCtrl', ['$scope', 'Upload', '$timeout', function ($scope, Upload, $timeout) {
$scope.uploadFiles = function(files, errFiles) {
$scope.files = files;
$scope.errFiles = errFiles;
angular.forEach(files, function(file) {
file.upload = Upload.upload({
url: 'https://angular-file-upload-cors-srv.appspot.com/upload',
data: {file: file}
});
file.upload.then(function (response) {
$timeout(function () {
file.result = response.data;
});
}, function (response) {
if (response.status > 0)
$scope.errorMsg = response.status + ': ' + response.data;
}, function (evt) {
file.progress = Math.min(100, parseInt(100.0 *
evt.loaded / evt.total));
});
});
}
}]);
这样,每个文件对象都会显示自己的进度条。但是,我想显示类似“一般进度条”的东西,它将通过这样的函数递增:
$scope.totalProgress = function (value) {
$scope.totProgress += value / $scope.files.length;
};
天真地想,这会奏效,但我很害怕我会在$scope.totProgress += value / $scope.files.length;
的竞争条件下招致。
那么,使用ng-file-upload multiple(逐个)上传的唯一进度条是否会出现竞争条件?
如果是,我怎样才能在$scope.totProgress
变量上正确实现互斥/信号?
提前谢谢!