2021年3月8日星期一

Returning a nested observable

Given this method:

public logIn(data:any): Observable<any> {    this.http.get('https://api.myapp.com/csrf-cookie').subscribe(() => {      return this.http.post('https://api.myapp.com/login', data);    });  }  

I would like it to return that nested observable, so that my calling code can use it like so:

this.apiService.logIn(credentials).subscribe(() => {      // redirect user to their dashboard  });  

without needing to know about the first /csrf-cookie request. Obviously the above doesn't work - but I'm struggling to understand how to make the inner HTTP request wait for the outer one to finish AND be returned by the method.

https://stackoverflow.com/questions/66540469/returning-a-nested-observable March 09, 2021 at 11:41AM

没有评论:

发表评论