【发布时间】:2019-02-26 13:43:18
【问题描述】:
我有以下问题; Observable 总是返回 undefined。 我想我真的不明白我需要如何使用 HttpClient 来使用 AuthGuard。
canActivate(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable < boolean > {
var bool
var token = localStorage.getItem('Authorization');
if (token != null) {
this.http.post('http://localhost:5000/v1/logstatus?token=' + token, this.authData).subscribe(res => {
if (!JSON.stringify(res).includes('AuthorizationNotFound')) {
bool = true
} else {
bool = false
}
})
} else {
bool = false
}
console.log(bool)
return observableOf(bool)
}
【问题讨论】:
标签: javascript angular post httpclient