未处理的承诺拒绝:您提供了'undefined'需要流的位置。使用 SwitchMap 和 Observable 类型的函数



这是我第一次使用rxjs库中的switchMap

我猜这个错误信息意味着它对我做事的方式不满意。

观察我的addemail功能

addemail(form:NgForm){
this.googlerecaptchaservice.verifyinteraction('general_marketing_email_signup')
.subscribe(
(score: any)=>{
console.log(score);
const value = form.value.emailaddform;
this.addemailservice.add_email_to_general_marketing(value)
.subscribe(
(req: any)=>{
console.log('here is the test');
console.log(req);
}
);
});
}

更具体地说是googlerecaptchaservice.verifyinteraction

verifyinteraction(action): Observable<any>{
return this.recaptchaV3Service.execute(action).pipe(
switchMap((value: any) => {
const payload = {
token: value
};
this.http.post(
'http://127.0.0.1:8000/verify/recaptcha', payload
);
}));
}

我不明白的是我为什么会出错。我做错了什么?

SwitchMap应该返回一个Observable,修改您的代码如下

verifyinteraction(action): Observable<any>{
return this.recaptchaV3Service.execute(action).pipe(
switchMap((value: any) => {
const payload = {
token: value
};
return this.http.post(
'http://127.0.0.1:8000/verify/recaptcha', payload
);
}));
}

SwitchMap需要一个Observable,所以您需要返回this.http.post

最新更新