forkjoin.subscribe引发无效的对象错误

时间:2019-05-10 21:47:26

标签: angular typescript

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[]),我不需要操纵结果,为什么它不起作用?

0 个答案:

没有答案