【发布时间】:2018-01-03 13:41:34
【问题描述】:
您好,我正在制作一个 Angular 5 的登录页面。我的方法如下:
login(context: LoginContext): Observable<number> {
let profileId: number;
this.http.post<AuthRes>(SERVER_API_URL + "api/authenticate", context).subscribe(authRes => {
profileId = authRes.profileId;
this.tokenService.setToken(authRes.token, context.rememberMe);
});
return of(profileId);
}
我的问题是有时,profileId 在第一个 observable 完成工作之前返回为 observable,当我尝试验证用户是否登录时,我得到了错误的结果。
我只想在我的第一个 observable 执行后返回 profileId。
谢谢
【问题讨论】:
-
订阅无法返回
标签: angular rxjs observable