订阅错误是这部分 .
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 {
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上的ErrorObservable.push ../ node_modules / rxjs / _esm5 / internal / Observable.js.Observable._trySubscribe(Observable.js:42)中的函数.. / node_modules / rxjs / _esm5 / internal / Observable.js.Observable.subscribe(Observable.js:28)at subscribeTo.js:21 at subscribeToResult(subscribeToResult.js:11)at CatchSubscriber.push ../ node_modules / rxjs / _esm5 / internal / operators /在MapSubscriber.push上的MapSubscriber.push ../ node_modules / rxjs / _esm5 / internal / Subscriber.js.Subscriber._error(Subscriber.js:83)中的catchError.js.CatchSubscriber.error(catchError.js:43) filterSubscriber.push上的node_modules / rxjs / _esm5 / internal / Subscriber.js.Subscriber.error(Subscriber.js:61)../ node_modules / rxjs / _esm5 / internal / Subscriber.js.Subscriber._error(Subscriber.js:83) )在MergeMapSubscriber.push上的FilterSubscriber.push ../ node_modules / rxjs / _esm5 / internal / Subscriber.js.Subscriber.error(Subscriber.js:61)../ node_modules / rxjs / _esm5 / internal / OuterSubscriber.js.OuterSubscribe r.notifyError(OuterSubscriber.js:13)
避免错误的最佳方法是什么?
我只需要两个imageLinks .