gpt4 book ai didi

javascript - 从服务器发送请求时发生合并映射错误

转载 作者:行者123 更新时间:2023-12-02 22:25:59 25 4
gpt4 key购买 nike

我有一个 Angular 应用程序,我正在通过服务调用执行发布请求。

但是我收到一个错误。但服务调用发送请求。所以这是一个非常具有误导性的错误。

这是我的方法:

sendEcheq(patientId: string) {
if (this.sendEcheq.length > 0) {

of(this.echeqsToSend)
.pipe(
mergeMap(echeqsToSend =>
forkJoin(
echeqsToSend.map((echeqFamily) =>
this.echeqSubmissionMedicalService.createSubmissionBatch(1, {
echeqFamilies: [
echeqFamily.family
],
participants: [
patientId

]
}).subscribe(result => {
console.log(result);
})
)
)
)
)
.subscribe(
result => {
this.dialog.close();
this.snackBar.open('De vcheq(s) zijn verstuurd', 'Ok');
},
error => {
console.error('Server error when assigning vcheq', error);
this.snackBar.open('Er ging iets mis bij het opsturen, probeer het later nog een keer', 'Ok');
this.dialog.close();
}
);
}
}

因此,如果我执行服务方法:createSubmissionBatch,那么它就会起作用。但我仍然收到此错误:

echeq-selector.component.ts:89 Server error when assigning vcheq TypeError: You provided an invalid object where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.
at subscribeTo (subscribeTo.js:41)
at subscribeToResult (subscribeToResult.js:11)
at new ForkJoinSubscriber (forkJoin.js:42)
at Observable._subscribe (forkJoin.js:28)
at Observable.push../node_modules/rxjs/_esm5/internal/Observable.js.Observable._trySubscribe (Observable.js:43)
at Observable.push../node_modules/rxjs/_esm5/internal/Observable.js.Observable.subscribe (Observable.js:29)
at subscribeTo.js:21
at subscribeToResult (subscribeToResult.js:11)
at MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/mergeMap.js.MergeMapSubscriber._innerSub (mergeMap.js:74)
at MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/mergeMap.js.MergeMapSubscriber._tryNext (mergeMap.js:68)

当然,我首先用谷歌搜索了这个错误。但我只发现 andswares 与其他东西相关,比如这个 answare:

TypeError: You provided an invalid object where a stream was expected. You can provide an Observable, Promise, Array, or Iterable

最佳答案

您返回的是 Subscription 而不是流,因为您有一个内部 .subscribe 来打印您的结果。

您应该将结果通过管道传递给 tap 操作并在那里打印,因为 tap 不会修改返回的流。

sendEcheq(patientId: string) {
if (this.sendEcheq.length > 0) {
of (this.echeqsToSend)
.pipe(
mergeMap(echeqsToSend =>
forkJoin(
echeqsToSend.map((echeqFamily) =>
this.echeqSubmissionMedicalService.createSubmissionBatch(1, {
echeqFamilies: [
echeqFamily.family
],
participants: [
patientId

]
}).pipe(
tap(result => console.log(reslult))
)
)
)
)
).subscribe(
result => {
this.dialog.close();
this.snackBar.open('De vcheq(s) zijn verstuurd', 'Ok');
},
error => {
console.error('Server error when assigning vcheq', error);
this.snackBar.open('Er ging iets mis bij het opsturen, probeer het later nog een keer', 'Ok');
this.dialog.close();
}
);
}
}

关于javascript - 从服务器发送请求时发生合并映射错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59070624/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com