【问题标题】:Dynamic Querying in AngularFirestore2 with snapshotChanges()在 AngularFirestore2 中使用 snapshotChanges() 进行动态查询
【发布时间】:2018-06-16 20:48:30
【问题描述】:
【问题讨论】:
标签:
angularfire2
google-cloud-firestore
【解决方案1】:
::facepalm::
似乎它与正常流式传输相同。对于那些无论如何感兴趣的人:
this.sizeFilter$ = new BehaviorSubject(null);
this.colorFilter$ = new BehaviorSubject(null);
this.items$ = Observable.combineLatest(
this.sizeFilter$,
this.colorFilter$
).switchMap(([size, color]) =>
afs.collection('items', ref => {
let query : firebase.firestore.CollectionReference | firebase.firestore.Query = ref;
if (size) { query = query.where('size', '==', size) };
if (color) { query = query.where('color', '==', color) };
return query;
}).snapshotChanges()
.map(actions => {
return actions.map(a => {
const data = a.payload.doc.data() as any;
const id = a.payload.doc.id;
return {id, ...data};
});
})
);