Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using input type file with angular material 2

Tags:

How can I use angular material 2 FAB buttons to open a browse input dialog? This can be done in HTML by this way.

<button type="button">     <label for="file-input">click</label> </button> <input type="file" id="file-input" style="display:none"> 

I tried following the same approach with material 2, but it doesn't work.

<button md-mini-fab type="button">     <label for="fileToUpload">         <md-icon>add</md-icon>     </label> </button> <input id="fileToUpload" type="file" style="display:none;"> 

Are there any other ways that will work? Thank you.

like image 546
Saif Avatar asked May 23 '17 09:05

Saif


People also ask

What is Matinput?

Matinput is an Angular directive that primarily allows input and text area elements to work with a form field. With this, you can display placeholders perfectly, add custom error messages, a clear button, specify the maximum length of the text or add prefixes and suffixes for a seamless user experience.

What is MatFormFieldControl?

MatFormFieldControl. An interface which allows a control to work inside of a MatFormField .


1 Answers

Here is a simple solution:

<button (click)="fileInput.click()">   <md-icon>library_add</md-icon>   <span>Select</span>   <input #fileInput type="file" (change)="onFileInput($event)" style="display:none;" /> </button> 
like image 138
rhyttr Avatar answered Sep 28 '22 19:09

rhyttr