订阅 canload guard Angular 2
Supscription in canload guard Angular2+
我正在尝试在 canload guard 中使用 combineLatest,但出现此错误:类型 'Subscription' 缺少类型 'Observable' 中的以下属性:_isScalar,源,操作员、电梯和其他 6 个。
我的代码如下所示:
canLoad(route: Route): Observable<boolean> {
return combineLatest(this.router.events, this.resources$, this.role$)
.subscribe(([nav, res, role]) => {
// some logic
return false;
})
}
我想监听路由事件并通过路由 slug 检查权限。有人可以帮助我吗?
您不必 subscribe
只需 return combineLatest
。
方法除了一个Observable
但是你return一个Subscription
.
canLoad(route: Route): Observable<boolean> {
return combineLatest(this.router.events, this.resources$, this.role$)
.pipe(
// take the first value emitted and complete
first()
map((value) => {
if(value) {
return true;
}
return false;
})
)
}
我正在尝试在 canload guard 中使用 combineLatest,但出现此错误:类型 'Subscription' 缺少类型 'Observable' 中的以下属性:_isScalar,源,操作员、电梯和其他 6 个。
我的代码如下所示:
canLoad(route: Route): Observable<boolean> {
return combineLatest(this.router.events, this.resources$, this.role$)
.subscribe(([nav, res, role]) => {
// some logic
return false;
})
}
我想监听路由事件并通过路由 slug 检查权限。有人可以帮助我吗?
您不必 subscribe
只需 return combineLatest
。
方法除了一个Observable
但是你return一个Subscription
.
canLoad(route: Route): Observable<boolean> {
return combineLatest(this.router.events, this.resources$, this.role$)
.pipe(
// take the first value emitted and complete
first()
map((value) => {
if(value) {
return true;
}
return false;
})
)
}