这是我第一次使用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