onUpload(event) {
let files: File[] = event;
files.forEach(file => {
const formData = new FormData();
formData.append('file', file);
formData.append('dsId', this.rdd.tech_id);
this.rddService.upload(formData).subscribe(response => {
// Do Something
})
})
}
有办法吗?
答案 0 :(得分:1)
尝试forkJoin
。 https://www.learnrxjs.io/learn-rxjs/operators/combination/forkjoin
import { forkJoin } from 'rxjs';
onUpload(event) {
let files: File[] = event;
forkJoin(
// spread the array of requests
// in the map we do the appropriate modifications as well
...files.map(file => {
const formData = new FormData();
formData.append('file', file);
formData.append('dsId', this.rdd.tech_id);
return this.rddService.upload(formData)
})
).subscribe(data => {
console.log('All done', data);
});
}