简体   繁体   中英

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

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

TeraData file-upload example

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM