Service {
uploadPhotos (id: string, images) {
const list$: Observable<any>[] = [];
for (let i = 0; i < images.length; i++) {
const uploadData = new FormData();
uploadData.append('file', images[i]);
list$.push(this.http.post(this.utils.apiRequest(`API`), uploadData,
{responseType: 'text'}));
}
return forkJoin(list$);
}
Class {
onUpload() {
try {
this.myService.uploadPhotos(this.id, this.selectedFiles).subscribe(() => {
...
});
} catch (error) {
console.log(error);
}
}
点击上传按钮后,我在TypeError: You provided an invalid object where a stream was expected. You can provide an Observable, Promise, Array, or Iterable
上看到了this.myService.uploadPhotos
。
uploadPhotos
方法返回Observable(any[])
,我不需要操纵结果,为什么它不起作用?