19

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 1

65

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.

Sign up to request clarification or add additional context in comments.

4 Comments

That's it, thanks! Btw, any difference putting button and input side-by-side instead of nesting the input inside button?
No problem! I believe there's no difference.
Perfect @PeterKim - exactly what I needed to. Thank you.
The greatest answer of all times. Thanks a lot. Upvoted

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.