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?
1 Answer
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.
4 Comments
galki
That's it, thanks! Btw, any difference putting
button and input side-by-side instead of nesting the input inside button?Peter Kim
No problem! I believe there's no difference.
Huw Roberts
Perfect @PeterKim - exactly what I needed to. Thank you.
AllJs
The greatest answer of all times. Thanks a lot. Upvoted