【发布时间】:2017-07-12 21:05:33
【问题描述】:
this.api.one('profiles', ui.sub).get() 下面代码中的内部 http 调用没有执行,我不知道为什么。我希望因为内部 map 调用返回一个 Observable 并被 flatMap 包装,所以我只需要在最后调用一次 subscribe() 但似乎我错了。
this.$http.get(uiUri, {headers: new Headers({'Authorization': 'Bearer ' + user.access_token})})
.map(resp => resp.json())
.flatMap((ui: IID4UserInfo) => {
let partialAccount = new Account(ui);
partialAccount.isLoggedIn = false;
this.currentAccount = partialAccount;
return this.api.one('profiles', ui.sub).get().map((profile) => {
this.currentAccount = new Account(profile.plain()); //never executes
this.storage.set('accountService.localAccount', this.currentAccount);
this.currentAccount.isLoggedIn = true;
this.accountSource.next(this.currentAccount);
if (this.loader)
this.loader.dismiss();
return this.currentAccount;
}, (err) => {
this.log.error(err);
this.currentAccount = partialAccount;
this.accountSource.next(partialAccount);
if (this.loader)
this.loader.dismiss();
return this.currentAccount;
})
})
.subscribe((profile) => {
this.log.info('user fully loaded');
}, err => {
this.log.error(err)
});
仅供参考this.api.one('profiles', ui.sub).get() 解析为:
get(queryParams?: string, headers?: any): Observable<IElement> {
let path = queryParams ? this.currentPath + '?' + queryParams : this.currentPath;
return this.api.http.get(path, {headers: this['_getHeaders'](headers)}).map(r => r.json()).map(resp => {
return Object.assign(new Element(this.api, this.currentPath), resp);
});
}
【问题讨论】: