角度|如何从.subscribe获得两个以上的返回值

时间:2018-11-09 08:50:09

标签: angular angular5 return-value subscribe

订阅错误是这部分。

this.commentService
        .uploadCommentImage(formData)
        .subscribe(
            data => {
               console.log(data);
            }, (err) => {
               console.error(err); // Error occurred!
            }
        );

commentService.uploadCommentImage-> postImage

uploadCommentImage(image: any) {
    return this.apiService.postImage('/api/comment/image', image);
  }

最后的通话部分就是这个部分。

postImage(path: string, image: Object = {}): Observable<any> {
    return this.httpClient
      .post(`${environment.api_url}${path}`, image)
      .pipe(catchError(this.formatErrors));
}


服务器的返回值(.subscribe(data))是:

{"imageLink":"assets/comment/image/a@a.aa_a48bd8e9.png"}{"imageLink":"assets/comment/image/a@a.aa_6cb66de4.png"}


在这种情况下,Angular上会发生错误。

  

TypeError:this._subscribe不是函数 ,位于ErrorObservable.push ../ node_modules / rxjs / _esm5 / internal / Observable.js.Observable._trySubscribe   (Observable.js:42)       在ErrorObservable.push ../ node_modules / rxjs / _esm5 / internal / Observable.js.Observable.subscribe中   (Observable.js:28)       在subscribeTo.js:21       在subscribeToResult(subscribeToResult.js:11)       在CatchSubscriber.push ../ node_modules / rxjs / _esm5 / internal / operators / catchError.js.CatchSubscriber.error中   (catchError.js:43)       在MapSubscriber.push ../ node_modules / rxjs / _esm5 / internal / Subscriber.js.Subscriber._error中   (Subscriber.js:83)       在MapSubscriber.push ../ node_modules / rxjs / _esm5 / internal / Subscriber.js.Subscriber.error中   (Subscriber.js:61)       在FilterSubscriber.push ../ node_modules / rxjs / _esm5 / internal / Subscriber.js.Subscriber._error中   (Subscriber.js:83)       在FilterSubscriber.push ../ node_modules / rxjs / _esm5 / internal / Subscriber.js.Subscriber.error中   (Subscriber.js:61)       在MergeMapSubscriber.push ../ node_modules / rxjs / _esm5 / internal / OuterSubscriber.js.OuterSubscriber.notifyError中   (OuterSubscriber.js:13)


避免错误的最佳方法是什么?

我只需要两个imageLink。

0 个答案:

没有答案