1

this is my first time using switchMap from the rxjs library.

Im guessing this error message means its unhappy with how I am doing things.

Observe my addemail function

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

  }

more specifically the 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
        );

      }));
  }

what I don't understand is why am I getting the error. What am I doing wrong?

2 Answers2

1

SwitchMap should return an Observable, modify you code as following

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

      }));
  }
Rafi Henig
  • 5,950
  • 2
  • 16
  • 36
  • oh ok so I still have to return the observable when using operators like `swtichMap` thank you. I will accept your answer when it allows me to. –  Aug 24 '20 at 00:02
0

SwitchMap expects an Observable so you need to return this.http.post

Alexander
  • 3,019
  • 1
  • 20
  • 24