【问题标题】:How to use orderBy with snapshotChanges() in Firestore Angular7如何在 Firestore Angular7 中使用 orderBy 和 snapshotChanges()
【发布时间】:2019-08-25 07:22:23
【问题描述】:

我想使用此代码在 Firestore 中订购“员工”文档的“全名”。

在 service.ts 中

 getEmployees() {   
    return this.firestore.collection('employee').snapshotChanges();
  }

在 Component.ts 中

  ngOnInit() {
            this.service.getEmployees().subscribe(actionArray => {
           let array = actionArray.map(item => {
             return {
               id: item.payload.doc.id,
               ...item.payload.doc.data()
             };

           });
         ....
}     

我是初学者。我需要对此代码进行哪些更改才能获得所需的输出。谢谢

【问题讨论】:

    标签: angular google-cloud-firestore angular7


    【解决方案1】:

    我假设您使用的是 Angular Firestore。 试试这个:

    getEmployees() {
    return this.firestore.collection('employee', ref => ref.orderBy('name','desc')).snapshotChanges(); }

    【讨论】:

      猜你喜欢
      • 2019-07-12
      • 1970-01-01
      • 2018-03-19
      • 2021-11-09
      • 1970-01-01
      • 2021-01-08
      • 1970-01-01
      • 1970-01-01
      • 2021-06-21
      相关资源
      最近更新 更多