【问题标题】:How to handle file upload using Angular2 Formbuilder?如何使用Angular2 Formbuilder处理文件上传?
【发布时间】:2017-06-09 07:16:54
【问题描述】:

在 Angular Docs 中似乎缺乏适当的文档。 Angular2 的最终版本还比较年轻,所以互联网上没有太多帮助。

如果有人能指导我使用 Angular 2.1

中的 FormBuilder 组件处理文件上传,我将不胜感激

【问题讨论】:

    标签: angular file-upload typescript2.0 angular2-formbuilder


    【解决方案1】:

    快速完成工作(根据您的需要进行修改):

    // Inside component
    fileUploaded(event: any) {
        const file = event.srcElement.files[0];
        this.form.get('file').patchValue(file);
    }
    
    // Inside template
    <input type="file" (change)="fileUploaded($event)">
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-23
      • 1970-01-01
      • 2017-02-01
      • 1970-01-01
      • 2012-06-30
      • 2016-02-07
      • 2021-07-12
      • 2011-01-15
      相关资源
      最近更新 更多