[英]How to return Firebase document property using Angular Firestore (Angular 7)?
I'm trying to get Firebase document property based on this model: 我正在尝试基于此模型获取Firebase文档属性:
I've already found a document using the following code: 我已经找到了使用以下代码的文档:
//Users - collection name, uid - document uid. //用户-集合名称,uid-文档uid。
Next, I'm trying to get isAdmin property using the following line of code: 接下来,我尝试使用以下代码行获取isAdmin属性:
In the results I receive undefined. 在结果中,我收到未定义。
How it can be resolved? 如何解决? I need to return
isAdmin
property value, but I don't get how to do it. 我需要返回
isAdmin
属性值,但是我不知道该怎么做。
The solution was very easy: 解决方案非常简单:
canActivate(): Observable<boolean> {
return this.auth.user$
.pipe(
switchMap(fireuser => this.userService.get(fireuser.uid).snapshotChanges()),
map(document => document.payload.data().isAdmin)
)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.