angular - 如何仅获取在 Firestore 上注册的相关数据
问题描述
我想检查“userId”并只获取在 Firestore 上注册的相关数据,但在 Firestore 上注册的所有内容都会打印出来。我不知道要修复哪个部分。我试图根据建议更改它,但它没有改变。对不起,我需要你的帮助。
应用程序组件打字稿代码是,
constructor(...) {
this.userId = authService.currentUserId; // for load uid data
this.userCollection = afs.collection<User>('users/'+this.userId);
this.user$ = this.userCollection.snapshotChanges().pipe(
map(actions => {
return actions.map(a => {
const data = a.payload.doc.data() as User;
const id = a.payload.doc.id;
id == this.userId;
return { id, ...data };
});
})
);
}
<ion-item *ngFor="let data of user$ | async">
<ion-label>
{{data.myName}}
<p>{{data.userId}}</p>
</ion-label>
</ion-item>
解决方案
尝试这个。
this.user$ = afs.doc<User>('users/' + this.userId).snapshotChanges().pipe(
map(action => {
const data = action.payload.doc.data() as User;
const id = action.payload.doc.id;
return { id, ...data };
})
);
推荐阅读
- http - IIS 服务器状态 500 错误 0x8007000d - web.config 中的“格式错误的 xml 元素”是什么?
- rust - 如何将特征对象转换为“子特征”对象?
- bash - 为需要引号的命令构造参数
- c - 读取整个管道 - c
- c# - 错误不支持文件的磁盘结构...找到 11.1,支持 12.0
- tensorflow - 运行 tensorflow 的 object_detection_model (下载模型出错)
- python - 迭代python中的不同函数
- vb.net - 如何在 Visual Basic 中将字符串转换为十进制?
- animation - 在 Xamarin.Forms.Core.Animation 上使用 TranslateTo 来制作动画?
- vim - 为什么这个 vim 函数不能工作,而是作为 cmd 运行