Angular canActive()不返回值?
帮我检查下面的代码。怎么了Angular canActive()不返回值?,angular,Angular,帮我检查下面的代码。怎么了 this.authenticationService.isLogin().subscribe(s => { if (s == 10) { this.router.navigate(['/dashboard']); return false; } }, e => { // console.log(e);
this.authenticationService.isLogin().subscribe(s => {
if (s == 10) {
this.router.navigate(['/dashboard']);
return false;
}
}, e => {
// console.log(e);
return true;
})
如果您订阅可观察对象,它将被消费。您应该做的是使用
map
操作符转换由可观察对象包装的值
在这里,尝试一下:
如果您使用的是Rxjs 5.5或更新版本:
import { map, catchError } from 'rxjs/operators';
import { of } from 'rxjs';
...
return this.authenticationService.isLogin().pipe(
map(s => {
if (s == 10) {
this.router.navigate(['/dashboard']);
return false;
} else {
// Not sure if this is what you want to return.
// But there needs to be an else condition as well for this.
return true;
}
}),
catchError(error => of(true))
)
如果您使用的是Rxjs 5或更早版本:
import 'rxjs/add/operator/map';
...
return this.authenticationService.isLogin()
.map(s => {
if (s == 10) {
this.router.navigate(['/dashboard']);
return false;
} else {
// Not sure if this is what you want to return.
// But there needs to be an else condition as well for this.
return true;
}
});
美好的我会努力的!此代码是否属于
canActive()
route gaurd?