【发布时间】:2020-02-01 14:26:36
【问题描述】:
我是 RxJS 的新手
这是我的功能
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也是一个observable,类似的函数,调用API,返回token。我想等到getTemptoken 返回值,然后只执行下一行,即下面的代码 if block
【问题讨论】:
标签: angular async-await rxjs observable