[英]How Can I assign the SnapshotChanges in a Observable Firebase Variable?
I want to load all the data of a document, but I can not access the id of the document.我想加载文档的所有数据,但我无法访问文档的 id。 When i print the object this.ressobj the id is visible, but when i put the ressobj.id_doc in the card the id id of the document is not visible.
当我打印对象 this.ressobj 时,id 是可见的,但是当我将 ressobj.id_doc 放入卡片时,文档的 id id 不可见。
this.ResColeccion = this.resser.getSpecificlistRestaurants(this.id); this.ResObservable$ = this.ResColeccion.snapshotChanges().subscribe(usuariolista =>{ this.ressobj=usuariolista.map(res =>{ return{ nombre:res.payload.doc.data().nombre, logo:res.payload.doc.data().logo, descripcion:res.payload.doc.data().descripcion, portada:res.payload.doc.data().portada, idadmin:res.payload.doc.data().idadmin, id_doc:res.payload.doc.id } }); console.log(this.ressobj); });
HTML CODE HTML代码
<ion-card *ngFor="let ressobj of ResObservable$ | async " [routerLink]="['/opcionesrestaurante',ressobj.id_doc]" > <img src="{{ressobj.portada}}"> <ion-card-content> <ion-card-title> <h1>{{ressobj.nombre}}</h1> </ion-card-title> <p>{{ressobj.descripcion}}</p> </ion-card-content> </ion-card>
Thanks for your help谢谢你的帮助
Not tested but I've used something like that for my angularfire2 projects:未经测试,但我在我的 angularfire2 项目中使用了类似的东西:
Getting a document:获取文档:
const ResObservable$ = () => {
return this.ResColeccion
.snapshotChanges()
.pipe(
map(actions => {
const data = actions.payload.data() as any;
const uid = actions.payload.id;
return { uid, ...data};
})
);
}
ResObservable$.subscribe(item => console.log(item)) // or use async
Getting a collection:获取集合:
const ResObservable$ = () => {
return this.ResColeccion
.snapshotChanges()
.pipe(
map(actions => {
return actions.map(a => {
const data = a.payload.doc.data() as any;
const uid = a.payload.doc.id;
return { uid, ...data };
});
})
);
}
ResObservable$.subscribe(items => console.log(items)) // or use async pipe
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.