如果用户已经登录,我想收到电子邮件声明。
this.auth.idTokenClaims$.forEach(e => console.log(">>>>>>>>>>>>>"+e.email));
正在打印电子邮件
我想写这样的东西(因为e可以为空)
if((this.auth.isAuthenticated$ | async) === false){
this.auth.idTokenClaims$.forEach(e => {
this.cService.dash(e.email).subscribe(
data => { this.yeah = data},
err => console.error(err),
() => console.log('Main Content ')
)}
);
} else {
this.cService.dash(null).subscribe(
data => { this.yeah = data},
err => console.error(err),
() => console.log('Main Content from else '));
}
问题: if((this.auth.isAuthenticated$ | async) === false){
它说总是评估为假,因为
<块引用>此条件将始终返回 'false',因为类型 'number' 和 'boolean' 没有重叠。ts(2367)
或
<块引用>算术运算的左侧必须是“any”类型, 'number'、'bigint' 或枚举类型.ts(2362)
这些方面的东西
请谁能帮我解决这个问题
答案 0 :(得分:0)
如果 isAuthenticated$
是 Observable
或任何类型的 Subject
,我会尝试将 2 个流构建为 pipe
并执行类似的操作
this.auth.isAuthenticated$.pipe(
skipWhile( isAuthenticated => isAuthenticated),
switchMap( () => this.auth.idTokenClaims$ ),
...
).subscribe()
this.auth.isAuthenticated$.pipe(
skipWhile( isAuthenticated => !isAuthenticated),
switchMap( () => this.cService.dash(null) ),
...
).subscribe()
我的主要观点是,如果您可以给出每个有问题的变量的类型,那么末尾的 $
符号主要代表 Subject
或 Observable
所以我不真的不明白 forEach 在没有订阅的情况下必须做什么