Why am I getting an error saying the item property of a FileList variable is not a function?
To clarify, I retrieve all files from a file input and store them in an array as type FileList successfully:
files: any = [];
onImageSelect(files: any = FileList) {
for(let i = 0; i < files.length; i++) {
this.files.push(files.item(i));
}
console.log(this.files)
}
The above onImageSelect method executes when the file input changes:
<input type="file" accept="image/*" multiple #fileUploader id="fileUploader" (change)="onImageSelect($any($event.target).files)">
Now that I have an array of selected files stored as type FileList, I aim to upload each file to Firebase by adding them to a NEW array also as type FileList:
filesUploaded: any = [];
uploadImages(selectedFiles: any = this.files) {
for (let i = 0; i < selectedFiles.length; i++) {
this.filesUploaded.push(selectedFiles.item(i));
}
}
The uploadImages method mentioned above is triggered on button click:
<button mat-raised-button color="secondary" (click)="uploadImages()">Upload</button>
However, upon execution, I encounter a type error message stating "ERROR TypeError: selectedFiles.item is not a function". What could be causing this issue?