嗨我想尝试获取角度的用户详细信息,并根据我需要执行特定任务的用户值,我能够调用api但响应是花了一些时间,这就是为什么我无法检查条件。
ngOnInit() {
this.getUserDetails();
if((this.user.PrivacyNotice))
{
------
}
else
{
------
}
}
getUserDetails() {
this.user.Email = "[email protected]";
this.bookingListSubscription = this.restService.getUserProfile(this.user).subscribe(
data => {
this.user = data;
});
}
这里user是UserVM Model类型的对象,它包含PrivacyNotice布尔字段
以下是进行api调用的服务方法
getUserProfile(user: UserVM): Observable<any> {
return this.http.post<UserVM>(this.getAPI('FetchUserProfile'),user,
this.httpOptions).pipe(
map(data => data),
catchError(this.handleError<any>('getUserProfile'))
);
}
如果我想检查从api返回的布尔标志PrivacyNotice的值,那么我怎么能得到这个。
只需在subscribe
回调中完成任务。
this.bookingListSubscription = this.restService.getUserProfile(this.user).subscribe(
data => {
this.user = data;
if((this.user.PrivacyNotice))
{
------
}
else
{
------
}
});
你可以查看这个链接,了解如何进行异步调用qazxsw poi