【发布时间】:2020-11-22 18:43:59
【问题描述】:
所以我试图在产品详细信息页面中显示我的产品,但我什么也没显示。 我不知道问题出在哪里。我真的需要一些帮助,因为如果这个问题没有得到解决,我将无法更进一步。谢谢大家。
product.service.ts
____________________
// Declarations
bayonete: Observable<CutiteInterface[]>;
loadBayonete: AngularFirestoreCollection<CutiteInterface>;
bayonetProd;
// get all products
GetBayonete() {
this.loadBayonete = this.afStore.collection("bayonete");
this.bayonetProd = this.loadBayonete.snapshotChanges().pipe(
map((action) => {
return action.map((a) => {
const data = a.payload.doc.data() as CutiteInterface;
const id = a.payload.doc.id;
return { id, ...data };
});
})
);
return this.bayonetProd;
}
// get single product
getProductDetails(id) {
return this.afStore.doc<CutiteInterface>("bayonete/" + id);
}
现在在我的详细信息页面中,我调用了我的产品,我可以在控制台中看到数组,但我无法显示它
detail-product.page.ts
_____________________
// Declarations
product?: CutiteInterface;
bayonetSingle: Observable<CutiteInterface[]>;
bayonetID: string;
constructor(
private route: ActivatedRoute,
private navCtrl: NavController,
private ProduseService: ProduseService,
private afStore: AngularFirestore
) {
this.bayonetID = this.route.snapshot.params["id"];
this.ProduseService.GetBayonete().subscribe((products) => {
this.product = products.find((a) => a.id === this.bayonetID);
console.log(this.product);
});
this.bayonetSingle = this.ProduseService.getProductDetails(
this.bayonetID
).valueChanges();
console.log(this.bayonetSingle);
}
这里我需要显示它:
product-detail.html
<ion-grid>
<ion-row>
<ion-col size="12">
<ion-list>
<div class="product_descriere">
{{ (bayonetSingle | async)?.description }}
</div>
<div class="product_reducere">
{{ (bayonetSingle | async)?.reducere }} Lei ( {{ (bayonetSingle | async)?.tag }} )
</div>
<div class="product_pret">
{{ (bayonetSingle | async)?.price }} Lei
</div>
</ion-list>
</ion-col>
</ion-row>
</ion-grid>
【问题讨论】:
-
这看起来不像 Firebase 的问题。首先,请不要告诉我们没有发生什么,告诉我们您希望看到什么以及您得到的实际输出是什么。例如,那些 console.log 行打印出来的是什么?其次,我可以看到您正在将信息检索到“产品”中,但您没有使用它来打印信息,您能否解释一下这是如何工作的?
标签: angular typescript firebase google-cloud-firestore angularfire2