【问题标题】:upload file with angular 5 and material上传带有角度5和材料的文件
【发布时间】:2018-02-20 16:24:51
【问题描述】:

我正在使用 Angular 5 和 material library。我需要上传一个文件,但在文档中,我没有找到完成此任务的解释。

有同样需要的人可以给我推荐一个好的教程或文档吗?

Tnx

【问题讨论】:

标签: angular file-upload material-design angular-material


【解决方案1】:

有一个很好的库可以处理这个也遵循 Marerial 设计的要求。见附件:

TeraData file-upload example

【讨论】:

  • 非常好的包。满满的爱
  • FileInput 是当前组件。
【解决方案2】:

我遇到了同样的问题,我使用 Angular Material 个性化了一个组件,没有外部库,并将所选文件的名称反馈到字段中:

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

【讨论】:

    猜你喜欢
    • 2021-01-02
    • 1970-01-01
    • 2015-09-10
    • 2018-04-26
    • 2019-05-23
    • 2020-09-20
    • 2020-03-04
    • 1970-01-01
    • 2017-01-12
    相关资源
    最近更新 更多