【发布时间】:2021-05-26 17:59:38
【问题描述】:
当我以这种方式查询 Firestore 数据库时,我无法获取文档的 ID:
你能给我一些帮助吗?
import { Component, OnInit } from '@angular/core';
import { AngularFirestore, AngularFirestoreCollection } from '@angular/fire/firestore';
import { Observable } from 'rxjs';
export interface Item { name: string; }
@Component({
selector: 'app-annonces-contactees',
templateUrl: './annonces-contactees.page.html',
styleUrls: ['./annonces-contactees.page.scss'],
})
export class AnnoncesContacteesPage implements OnInit {
private annoncesCollection: AngularFirestoreCollection<Item>;
annonces: Observable<Item[]>;
constructor(private afs: AngularFirestore) {
this.annoncesCollection = afs.collection('annonces', ref => ref.where('prix', '>=', 1000000))
this.annonces = this.annoncesCollection.valueChanges();
}
ngOnInit() {
}
}
【问题讨论】:
-
试试这个.. this.annoncesCollection..snapshotChanges().pipe( map(actions => actions.map(a => { const data = a.payload.doc.data() as Item ; const id = a.payload.doc.id; return { id, ...data }; }))
-
谢谢,但是如何在我的 html 代码中显示它?现在我用它来获得结果:
- {{ annonce.prix }}
-
你确定你的代码吗?我收到错误
标签: javascript ionic-framework google-cloud-firestore angularfire2