1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

Angular 5 how to get file name from input with type = file

Discussão em 'Angular' iniciado por Miger, Maio 26, 2025.

  1. Miger

    Miger Guest

    I know there are simmilar questions but none cover the method for Angular 5 or at least not in a way that I understand it.

    For my image upload system I need to know if a picture is attached to the input tag and what name the file has. Here is my code:

    HTML:

    <input
    type="file"
    [(ngModel)]="currentInput"
    (change)="onFileSelected($event)"
    >


    Angular:

    export class ImageUpload {
    currentInput;

    onFileSelected(event) {
    console.log(this.currentInput);
    }
    }


    No matter if there is a file attached or not the value in "currentInput" is always undefined. How does this work with input when the type is equal to "file"?

    Thanks!

    Continue reading...

Compartilhe esta Página