xcesco
xcesco

Reputation: 4838

upload file with angular 5 and material

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

Answers (2)

Rodrigo Bueno
Rodrigo Bueno

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:

enter image description here enter image description here

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

Narm
Narm

Reputation: 10834

There is a nice library that handles this requirement that also follows Marerial Design. See attached link:

TeraData file-upload example

Upvotes: 10

Related Questions