Get file name from input type file Angular2

Sandro De Marco picture Sandro De Marco · Feb 27, 2017 · Viewed 40.4k times · Source

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

Answer

Igor Janković picture Igor Janković · Feb 27, 2017

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;
}