未处理的承诺拒绝:您在期望流的位置提供了“未定义”使用SwitchMap和类型为Observable的函数

问题描述

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

我猜测此错误消息表示它对我的工作方式不满意。

观察我的class Container: def __init__(self,data=None): self.data = data or [] def __repr__(self): return str(self.data) x = {a} print(x) # {[]} a.data = [0,1,2] print(x) # {[0,2]} 函数

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);
              }
            );
        });

  }

我不明白的是为什么我会收到错误消息。我在做什么错了?

解决方法

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