Angular 2-FormArray +文件输入+本机元素

时间:2019-03-11 03:57:33

标签: angular typescript file-upload

我正在使用Angular 2上的反应式表单,但遇到问题了。

我的FormArray上有一个上载文件字段,我使用@ViewChild获取文件,并使用forEach遍历FormArray,数据工作正常,但文件输入没有。我要上传两次相同的文件。

有人可以帮我吗?

非常感谢您!

add.component.ts

@ViewChild('pictureInput') pictureInput: any;

bArray.forEach((element) => {
   // Picture Upload
   // Create an ID for the picture to be uploaded.
   const picUpId = this.createID();
   // Connects to the UPLOAD service to store the file
                        this.uploadService.uploadFile(this.pictureInput.nativeElement.files[0], picUpId, 'uploads/' + id + '/').then(
     (picData) => {
          // Extract the DownloadURL from the object.
          picData.ref.getDownloadURL().then(
               (picDownURL) => {
                    const bPicture = new ImageModel(picDownURL, id);
               }
          );

      }
);

add.component.html

<input type="file" formControlName="bPicture" #pictureInput>

0 个答案:

没有答案