【发布时间】:2018-05-16 06:54:27
【问题描述】:
所以,我试图解决这个问题。但是,不知何故我无法这样做,可能是因为缺乏角度 5 的知识。 这是我的服务:
GetCurrentUserData(): Observable<ResponseData> {
return this.http.get<ResponseData>(ApplicationURLS.GetCurrentUserInformation)
.map(response => {
return response;
});
//.catch(error => this.handleError(error));
}
这是我的组件:
public GetCurrentUserInformation(): any {
return this.loginService.GetCurrentUserData().subscribe(data => { return data; });
}
我在这里尝试访问数据:
ngAfterViewInit() {
debugger;
this.responseData = this.GetCurrentUserInformation();
if (this.responseData.code != responseCodes.success) {
this.googleInit();
}
}
当我检查 this.responseData 它总是返回这个而不是我想要数据:
我只想进行同步调用,以便立即获取数据。
我也尝试在服务中使用 do(),但它返回的 do() 不是函数。
【问题讨论】:
-
我认为 async/await 可能是这里最好的情况????
-
@malbarmawi 是的
标签: angular typescript service angular-services angular-components