使用 firestore ionic 4 从集合中获取数据
Get data from a collection with firestore ionic 4
我想从带有 firebase firestore 的集合中的文档中获取唯一数据
所以我用来获取所有数据:
ngOnInit() {
return this.firestore.collection('users').snapshotChanges()
.subscribe(data => {
console.log(data);
this.utilisateurs = data;
console.log(this.passided);
});
}
这是为了获得唯一的 id :
this.passided = this.navParams.get('id');
我试着这样做:
return this.firestore.collection('users').doc(this.passided).snapshotChanges()
但是不工作,你能帮我吗?
snapshotChanges()
是 class AngularFirestoreCollection
中的一个方法,其中 returns 数据的 Observable 作为 DocumentChangeAction
.
如果你想对文档进行操作,那么你可以使用以下方法:
set(data: T)
- 破坏性地更新文档的数据。
update(data: T)
- Non-destructively 更新文档的数据。
delete()
- 删除整个文档。不删除任何嵌套集合。
因此,this.firestore.collection('users').doc(this.passided).snapshotChanges()
将无法工作,因为 snapshotChanges()
不是 document.ts
中的方法
供参考:
https://github.com/angular/angularfire2/blob/master/docs/firestore/documents.md#snapshotchanges
https://github.com/angular/angularfire2/blob/master/src/firestore/collection/collection.ts#L97
我想从带有 firebase firestore 的集合中的文档中获取唯一数据
所以我用来获取所有数据:
ngOnInit() {
return this.firestore.collection('users').snapshotChanges()
.subscribe(data => {
console.log(data);
this.utilisateurs = data;
console.log(this.passided);
});
}
这是为了获得唯一的 id :
this.passided = this.navParams.get('id');
我试着这样做:
return this.firestore.collection('users').doc(this.passided).snapshotChanges()
但是不工作,你能帮我吗?
snapshotChanges()
是 class AngularFirestoreCollection
中的一个方法,其中 returns 数据的 Observable 作为 DocumentChangeAction
.
如果你想对文档进行操作,那么你可以使用以下方法:
set(data: T)
- 破坏性地更新文档的数据。
update(data: T)
- Non-destructively 更新文档的数据。
delete()
- 删除整个文档。不删除任何嵌套集合。
因此,this.firestore.collection('users').doc(this.passided).snapshotChanges()
将无法工作,因为 snapshotChanges()
不是 document.ts
供参考: https://github.com/angular/angularfire2/blob/master/docs/firestore/documents.md#snapshotchanges
https://github.com/angular/angularfire2/blob/master/src/firestore/collection/collection.ts#L97