当我使用$scope.cancelUpload()
函数中止整个上传时,一切都取消了,除了我收到以下错误:
错误:undefined不是对象(评估'$ scope.file_upload.statusLog [evt.config.data.index] .percentage = progressPercentage')
我知道这个错误是由我在取消功能的最后一行中执行$scope.file_upload.statusLog = []
引起的,但我没有看到任何其他方法来清除状态百分比。他们需要被清除,因为我使用这个数组来显示上传文件时上传的百分比。
有没有人知道修复此错误的替代方法?
$scope.file_upload = { file_array: [], statusLog: [], uploadArray: [] };
$scope.startUpload = function() {
$scope.upload($scope.file_upload.file_array);
}
$scope.upload = function (files) {
$scope.file_upload.statusLog = new Array(files.length);
$scope.file_upload.uploadArray = new Array(files.length);
if (files && files.length) {
for (var i = 0; i < files.length; i++) {
var file = files[i];
if (!file.$error) {
$scope.file_upload.statusLog[i] = { percentage: 0, complete: false };
$scope.file_upload.uploadArray[i] = Upload.upload({
url: $rootScope.fileUploadURL, data: { index: i }
}).progress(function (evt) {
/* WHERE THE ISSUE LIES */
var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
$scope.file_upload.statusLog[evt.config.data.index].percentage = progressPercentage;
}).success(function (data, status, headers, config) { /* Stuff */ });
}
}
}
};
$scope.cancelUpload = function() {
for (var i = 0; i < $scope.file_upload.file_array.length; i++)
$scope.file_upload.uploadArray[i].abort();
$scope.file_upload.file_array = [], $scope.file_upload.statusLog = [], $scope.file_upload.uploadArray = [];
}