Search code examples
htmlangularangular2-templatehtml-input

Get file name from input type file Angular2


I want get the file name from my html input tag in a modal view and save it using Angular2. Can someone help me?


Solution

  • You can do next:

    HTML:

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

    TypeScript:

    fileEvent(fileInput: Event){
        let file = fileInput.target.files[0];
        let fileName = file.name;
    }