【问题标题】: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
【解决方案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;
}