所以,我尝试解决这个问题。但由于我在 Angular 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时,它总是返回这个,但我想要数据:
![enter image description here](https://istack.dev59.com/704lX.webp)
我只想发起同步调用,以便可以立即获取数据。
我也尝试在服务中使用do(),但它返回“do()不是一个函数”。