【发布时间】:2017-10-18 14:23:31
【问题描述】:
在我的情况下,我正在使用 auth guard CanActivate() 限制每个路由的用户访问,但是条件值取自 http 请求 Promise 对象。如何访问 Promise then() 和 catch() 并将其返回给CanActivate(): Boolean 函数?
我的代码看起来像这样。
// On AuthService
verfifyUser(): Promise<any> {
return this.http
.get(`api/auth/verify-user`, { headers: this.headers })
.toPromise()
.then(res => res.json() as any);
}
// On AuthGuardService
CanActivate(): Boolean {
this.authSrv.verfifyUser(some_user).then(result => {
// return true
}).catch(err => {
// return false
});
}
我仍然不知道如何解决这个问题。
【问题讨论】:
标签: angular typescript