angulartypescripttypescript-types

file Input Event type in Angular


So I have been using Angular and Typescript for a long time. I cannot seem to find out what the Type for an Input file is.

For example:

<input type="file" (change)="fileChangeEvent($event)">

fileChangeEvent(e:?????){}

All examples purely just uses event without any type, and I am curious to know if such a type even exists.


Solution

  • Use File

    The File interface provides information about files and allows JavaScript in a web page to access their content.

    Try this

    component.html

    <input type="file" (change)="fileChangeEvent($event.target.files)">
    

    component.ts

    fileChangeEvent(e: File[]){
        fileName = e[0];
        fileType = fileName.type;
    }