angular - Route guard 中的多个 observable 但只等待一个 - Angular 5
问题描述
我的应用程序中有一个路由守卫,如果有人成功,我需要检查两个可观察对象,我应该允许路由或阻止。
路线守卫:
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): any {
return (this.isValid().map(valid => {
console.log(valid);
return valid;
}) || this.isValidFromApi().map(valid => {
console.log(valid);
return valid;
}));
} //how to achieve something like this
}
private isValid() {
return this.service.details.map(resp => {
console.log(resp);
if (resp.data) {
return true;
} else {
return false;
}
});
}
private isValidFromApi() {
return this.service.getKeys().map((response) => {
console.log(response);
if (response) {
return true;
} else {
return false;
});
}
因此,如果 isValid() 或 isValidFromApi() 中的任何一个返回 true,则路由保护 canActivate 应该处于活动状态。如何做到这一点?我不想等待这两个调用完成,因为 this.service.details 实际上是一个 BehaviorSubject,它包含 this.service.getKeys() 的响应。
有没有其他方法可以实现这一目标?
提前致谢
解决方案
推荐阅读
- apache-spark - spark_apply 适用于一个数据集,但在另一个数据集上失败(两个数据集的类型和结构相同)
- mysql - Oracle 等效于 useServerPrepStmts=false & rewriteBatchedStatements=true
- excel - Workbooks.open 不返回任何内容
- visual-studio-code - VSCode 将打开的工作区列表存储在哪里?
- python - 将字典值转换为新字典
- php - 如何将 wordpress 博客作为路由添加到 Yii2 网站
- windows - 如何使用cmd中的嵌套for循环将目标文件替换为源位置的另一个文件
- python - 从 django 中的表中过滤掉空值
- java - 在同一上下文中使用 Spring Boot 2 OAuth Client 和 Resourcesserver
- java - 适配器抛出 java.lang.NullPointerException