Error rxjs_Observable__.Observable.forkJoin is not a function?

后端 未结 4 527
情深已故
情深已故 2021-02-05 10:25

I am using Rxjs in an angualr-cli application.

in viewer.component.ts

    //Other Imports
    import { Observable } from \'rxj         


        
4条回答
  •  时光说笑
    2021-02-05 11:00

    In one project I used the following forkjoin code to upload images, it works perfectly.

    /**
           *  Upload multiple image and then update the feature
           */
          public uploadImages(apiParams: any[], imageItems: any[]): Observable {
            if (imageItems.length === 0) return;
    
            let promises = [];
            for (let imageItem of imageItems) {
              promises.push(this.uploadImage(apiParams, imageItem));
            }
            return Observable.forkJoin(...promises);
          }
    
          /**
           * upload single image
           */
          public uploadImage(apiParams: any[], imageItem: any): any {
            let _formData = new FormData();
            _formData.append("UploadedImage", imageItem,  (new Guid()).toString()+'.png');
            const imageApiUrl = StringFormatter.format(imagePoints.create, apiParams);
            return Observable.fromPromise(
              fetch(imageApiUrl, {
                method: "POST",
                body: _formData
              })
              .then(result => result.json())
            );
          }
    

提交回复
热议问题