file Input Event type in Angular
Angular 10 and above:
component.html
<input type="file" (change)="upload($event)">
component.ts
upload(event: Event) {
const target = event.target as HTMLInputElement;
const files = target.files as FileList;
console.log(files);
}
For Angular 10 strict-type mode, we need to mention type in parameters. You can follow this way to achieve file-list from file input event
// HTML
<input type="file" (change)="uploadFile($event)">
// TS
uploadFile(event: Event) {
const element = event.currentTarget as HTMLInputElement;
let fileList: FileList | null = element.files;
if (fileList) {
console.log("FileUpload -> files", fileList);
}
}
Hope this helps. Please share your feedback.