Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

649
Vistas
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.

over 4 years ago · Santiago Trujillo
5 Respuestas
Responde la pregunta

0

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);
  }
over 4 years ago · Santiago Trujillo Denunciar

0

One line statement to get the file Type:

fileInput: any
fetchFileType($event);

fetchFileType(fileInput: any) {
  fileName = this.fileInput.target.files[0];
  fileType = fileName.type;
}
over 4 years ago · Santiago Trujillo Denunciar

0

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.

over 4 years ago · Santiago Trujillo Denunciar

0

The type is Event

fileChangeEvent(e: Event){}
over 4 years ago · Santiago Trujillo Denunciar

0

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;
}
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda