Angular 5 how to get file name from input with type = file
Try this below way
onFileSelected(event) {
if(event.target.files.length > 0)
{
console.log(event.target.files[0].name);
}
}
@ramesh-rajendran's answer is good. If you want the TypeScript solution:
onFileSelected(event: Event) {
const target = event.target as HTMLInputElement;
if (target.files && target.files.length > 0) {
console.log(target.files[0].name);
}
}