我正在使用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>