angular - 尝试使用 ngIf 订阅 observable 并进入循环
问题描述
这是用户登录时应该显示的图标的html:
<mat-icon class="logout-icon logout-spacer" *ngIf="(isLoggedIn() | async)" (click)="logout()" >exit_to_app</mat-icon>
该图标的组件如下所示
isLoggedIn(){
return this.authService.isLoggedIn().pipe(
take(1),
map((authState) => !!authState),
tap(user =>{
if (user){
console.log("user found");
} else {
console.log("user not found");
}
})
);
}
还有一个身份验证服务,它的代码显示在下面,由 AngularFire 库支持
isLoggedIn(){
return this.afAuth.authState.pipe(first());
}
当我在开发者控制台中运行应用程序时,我只能看到“找不到用户”反复显示。
提前致谢!
解决方案
推荐阅读
- npm - 是什么导致 npm 包安装差异
- python - LSTM 模型的时间序列数据输入引发错误
- algorithm - 查找仅覆盖“空闲”像素的最大非重叠矩形序列
- asp.net-web-api - 作为中央微服务 ASP.NET 的身份验证和授权
- python - 如何编写一个 Django 查询,其中我的 WHERE 条件的左侧是一个数学表达式?
- python - 如何惩罚 DataFrame 中的空字段?
- php - 让wordpress忽略文件夹作为主题
- sas - 尝试在 SAS 中格式化字段,忽略小数
- javascript - 从反应客户端应用程序到 spring-boot 服务器的 HTTP POST 请求返回 400 错误
- java - Rest web services(post)消耗json不工作