Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a custom file upload button in Angular

I'd like to replace the "Choose File" text and ugly styling of the <input type="file" /> button with some other text such as "Upload" and nice styling, perhaps using a mat-button. What is the cleanest way to achieve this without installing any extra file-upload packages?

like image 265
galki Avatar asked Dec 02 '18 21:12

galki


1 Answers

Use below template:

.html:

<button type="button" (click)="fileInput.click()">
  <span>Upload</span>
  <input #fileInput type="file" (change)="onFileInput($event)" style="display:none;" />
</button>

The on-click function will prompt the user to select a file.

like image 123
Peter Kim Avatar answered Nov 13 '22 20:11

Peter Kim