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

182
Vistas
How to limit the maximum uploads in Angular

How should i limit the maximum 5 uploads in a single input file in angular

<input type="file" class="form-control" id="inputGroupFile" 
onChange="uploadMultipleFiles($event)" > 

app.component.ts:

uploadMultipleFiles(files) {
  if (files.length > 3) {
   this.alertService.error("length exceeded; files have been truncated");
   let list = new DataTransfer;
   for (let i = 0; i < 3; i++)
    list.items.add(files[i]);
  }
}

Thanks

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Like the below code, you can prevent the limit of file upload.

filesData(files, event): void {
  
    if (event.target.files.length > 5) {
      alert("Only 5 files allow");

      event.preventDefault();
      event.value = ""; // clear the older value 
    } else {
        //Put your Business logic here
    }
  }

Also, pass the $event as an argument to the function on the calling the onChange method.

 <input type="file" multiple #file (change)="filesData($event)" />
about 4 years ago · Juan Pablo Isaza 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