I am very new in RxJS
Here is my function
getData(id): Observable<any> {
let accessToken = this.getAccessHeader();
if (!accessToken) {
// Here I want to wait till following observable completes, and returns value. Till then do not call next line methods i.e. code outside the if block
this.getTemptoken().subscribe((res) => {
accessToken = res.result.accessToken,
});
}
const httpOptions = {
headers: new HttpHeaders({
'accessToken': accessToken
})
};
return this.http.post(
url,
{
'id': id
}, httpOptions
).pipe(map((res) => {
return res;
}));
}
getTemptoken is also an observable, similar function, which calls API and returns token. I want to wait till getTemptoken returns value and after that only execute next lines, i.e. code below if block