I was creating a file upload component.
https://stackblitz.com/edit/stackblitz-starters-7rtzbt?file=src%2Fapp%2Ffile-upload%2Ffile-upload.component.ts
#Error:- NG9: Property 'files' does not exist on type 'EventTarget'.
1 messages · Page 1 of 1 (latest)
I have been through::->
Stack Overflow
I am trying to access the value of the input file from my ionic 2 application but still I'm facing the issue of property files does not exist on type 'EventTarget'.
As it is properly working in js ...
import { Component } from '@angular/core';
interface HTMLInputEvent extends Event {
target: HTMLInputElement & EventTarget;
}
@Component({
selector: 'app-file-upload',
standalone: true,
imports: [],
templateUrl: './file-upload.component.html',
styleUrl: './file-upload.component.css'
})
export class FileUploadComponent {
onFileSelected(event:HTMLInputEvent) {
const file:File|null = event.target!.files!.item(0);
if (file) {
console.log(file);
const formData = new FormData();
formData.append("file1", file);
console.log(formData);
}
}
}
You know that the target is an HTMLInputElement, so tell TypeScript:
(event.target as HTMLInputElement).files.items(0)