我正在尝试使用angular上传多个文件。一个例子是上载我选择4个文件。这是我到目前为止所做的。我尝试循环播放,但无法正常工作。
onChange(event) {
if (event.target.files.length > 0) {
this.filesToUpload = event.target.files;
}
}
saveFileForm() {
var formData = new FormData();
const files = this.filesToUpload;
for(let i = 0; i < files.length; i++) {
formData.append("files", files[i]);
this.coursemoduleService.uploadFile(
this.contentDetails.content.id,
formData).subscribe(
result => {
this.formMessageClass = "alert-success";
this.formMessage = "Content added!";
formAlert();
console.log(result);
},
error => {
console.log(error);
this.formMessageClass = "alert-danger";
this.formMessage = "Pls. fill required fields correctly!"
formAlert();
validateAllFormFields(this.fileForm);
}
);
}
}