简体   繁体   English

在角度Firestore文档上无法观察到

[英]Observable on angular firestore document not working

I'm trying to assign an observable of a firestore document to an attribute of a service. 我正在尝试将可观察到的Firestore文档分配给服务的属性。 I want to use it later with async pipe in template 我想稍后与模板中的异步管道一起使用

I tried in all ways but can't get it work. 我尝试了所有方法,但无法正常工作。 Some help would be really great. 一些帮助会真的很棒。

export class UserService {
    private currentUserObservable: Observable<User>;

    loadUserObservable(uid){ 
    this.currentUserObservable =this.afs.doc(`users/${uid}`).valueChanges()
    }
}

<div *ngIf="userService.currentUserObservable | async as user">
Displayname: {{ user.displayName }}
</div>

Well here you have an example of login library with sync user in database you can study it if you want to. 好了,这里有一个在数据库中带有同步用户的登录库示例,您可以根据需要进行研究。

Auth module: 验证模块:
https://bitbucket.org/mises543/fire-ngx-auth/src/master/projects/auth/src/lib/ https://bitbucket.org/mises543/fire-ngx-auth/src/master/projects/auth/src/lib/

example app using this module: 使用此模块的示例应用程序:
https://bitbucket.org/mises543/fire-ngx-auth/src/master/projects/auth-test/ https://bitbucket.org/mises543/fire-ngx-auth/src/master/projects/auth-test/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM