Angular 从firestore文档中读取值

Angular 从firestore文档中读取值,angular,typescript,firebase,ionic-framework,google-cloud-firestore,Angular,Typescript,Firebase,Ionic Framework,Google Cloud Firestore,我有一个使用此方法从firestore获取特定文档的服务 GetBidResistes(userId:string){ 返回此.firestore.collection('userProfile').doc(userId) 在typscript类中,我在ngOnInit中将此方法调用为 this.userInfo=this.firestoreService.getBidResistes(userid).valueChanges().subscribe(data=>console.log(data

我有一个使用此方法从firestore获取特定文档的服务

GetBidResistes(userId:string){ 返回此.firestore.collection('userProfile').doc(userId)

在typscript类中,我在ngOnInit中将此方法调用为 this.userInfo=this.firestoreService.getBidResistes(userid).valueChanges().subscribe(data=>console.log(data))

在控制台中,我可以看到数据被正确提取,但是当我尝试使用this.userInfo.remainBids时 它不打印任何内容。在控制台中显示为未定义

但是在html文件中(在删除.subscribe之后),我能够使用{{(userInfo | async)?.remainBids}从firebase打印正确的值 有人能帮我一下吗?我不确定我做错了什么。我想获取文档并能够读取文档中包含的字段的值

firestore数据库文档字段很简单,它包含电子邮件、名称和其他字段

这是firestore服务函数名GetBidResistes(userId:string)

这是进行调用的typescript类 this.userInfo=this.firestoreService.getbidsremains(userid).valueChanges().subscribe(数据=>console.log(数据));

如果需要this.userInfo.remainBids来获得剩余的出价,请在subscribe方法()中使用它


另外,不要忘记在Ngondestory中取消订阅。

userinfo
变量分配给
Subscription
,该订阅没有
remainBids
属性。 您需要在
subscribe
中指定变量,如下所示:

...subscribe(data => {this.userInfo = data})
this.userInfo = this.firestoreService.getBigremains(userid).valuechanges()
或者将您的
userInfo
变量设置为可观察变量,并按如下方式分配:

...subscribe(data => {this.userInfo = data})
this.userInfo = this.firestoreService.getBigremains(userid).valuechanges()

请向我们展示您的服务和页面/组件中的代码谢谢,已经添加了屏幕截图。谢谢,在订阅函数中分配变量确实有效!!!在堆栈溢出时,请不要显示代码和文本的图像。请将代码复制到问题本身并格式化,以便易于阅读。注意,请记住