Reputation: 4838
I'm working with Angular 5 and material library. I need to upload a file, but in the documentation, I didn't find an explanation to accomplish this task.
Is anybody that have the same need that can suggest me a good tutorial or documentation?
Tnx
Upvotes: 3
Views: 15043
Reputation: 91
I had the same problem and I personalized a component with Angular Material without external libs and feedback with the name of the chosen file into field:
HTML
<mat-form-field class="columns">
<mat-label *ngIf="selectedFiles; else newFile">{{selectedFiles.item(0).name}}</mat-label>
<ng-template #newFile>
<mat-label>Choose file</mat-label>
</ng-template>
<input matInput disabled>
<button mat-icon-button matSuffix (click)="fileInput.click()">
<mat-icon>attach_file</mat-icon>
</button>
<input hidden (change)="selectFile($event)" #fileInput type="file" id="file">
</mat-form-field>
TS
selectFile(event) {
this.selectedFiles = event.target.files;
}
Upvotes: 2
Reputation: 10834
There is a nice library that handles this requirement that also follows Marerial Design. See attached link:
Upvotes: 10