I am attempting to detect an event once a file has been uploaded using a file input.
Here is the JavaScript code:
fileSelected(e: Event) {
if ((<HTMLInputElement>e.target).files !== null && (<HTMLInputElement>e.target).files[0] !== null) {
this.file = (<HTMLInputElement>e.target).files[0];
}
}
My file variable is currently set to null. I am trying to access the first element of the files array, but it is throwing an error:
Object is possibly null
I have discovered that you need to verify if it's not empty first, but I still encounter the same error on the if statement itself. Any suggestions?