I'm very new to AngularJS and I need to implement a multiple file uploader.
I'm using danialfarid/angular-file-upload and the upload works great. However, I'm facing problems when it comes to updating my $scope.selectedFiles with the current upload progress.
Here is a fragment of my code:
angular.module('myApp', ['angularFileUpload', 'ui.bootstrap']);
var MyCtrl = [ '$scope', '$upload', function($scope, $upload) {
// ...
// This array store multiple files the user wants to upload
$scope.selectedFiles = [];
// Here the upload happens
$scope.uploadFiles = function() {
var files = $scope.selectedFiles;
for (var i = 0; i < files.length; i++) {
var file = files[i].fileObject;
$upload.upload({
//...
}).progress(function(evt) {
// p === current progress, this is working fine
var p = parseInt(100.0 * evt.loaded / evt.total));
// HERE IS THE ISSUE
// $scope.selectedFiles === undefined
// I need to find out a way to update $scope.selectedFiles[i].progres with the current progress....
var p = parseInt(100.0 * evt.loaded / evt.total);
console.log('$scope.selectedFiles: ' + $scope.selectedFiles); //[object Object]
console.log('$scope.selectedFiles[i]: ' + $scope.selectedFiles[i]); //undefined
console.log('$scope.selectedFiles[i].progress: ' + $scope.selectedFiles[i].progress); //Error: $scope.selectedFiles[i] is undefined
$scope.selectedFiles[i].progress = p;
})
// ...
Any help?
Thanks