angular - 未处理的承诺拒绝:您在预期流的位置提供了“未定义”。使用 SwitchMap 和 Observable 类型的函数
问题描述
这是我第一次使用switchMap
rxjs 库。
我猜这个错误信息意味着它对我做事的方式不满意。
观察我的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
);
}));
}
推荐阅读
- ios - 通过 iOS 共享扩展导入 p12 文件提供了错误的数据
- java - Bytebuddy - 拦截 java.lang.RuntimeException 构造函数
- r - 如何在搜索时填充闪亮的空数据表
- angular - Angular 9 无法在子模块中获取路由参数
- javascript - 类型错误:pub 不是函数
- python - AttributeError:无法删除属性
- java - Eclipse(Java,testng 项目):正在创建多个包
- mysql - 过滤掉不同的记录并保留最后一条
- c# - 如何获取第一个 xml 元素的值?
- sql-server - 在 Plesk microsoft sql server 2018 上导入转储时出错