如何在 Firestore Angular7 中使用 orderBy 和 snapshotChanges()

Sup*_*tha 0 angular google-cloud-firestore angular7

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

在 service.ts

 getEmployees() {   
    return this.firestore.collection('employee').snapshotChanges();
  }
Run Code Online (Sandbox Code Playgroud)

在 Component.ts 中

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

           });
         ....
}     
Run Code Online (Sandbox Code Playgroud)

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

Ind*_*ith 6

我假设您正在使用 Angular Firestore。尝试这个:

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