0

How do you sort(by key) a list of data coming from Firebase realtime database?

This is the HTML code for that i use

<div *ngFor="let transaction of getTransactionList | async">
{{ transaction.amount }}
</div>

And this is the javascript/angular code that i use to get the data from firebase.

import { Observable } from 'rxjs/Observable';

export class HomeComponent implements OnInit {

  getTransactionList: Observable<any[]>;

  constructor(public afAuth : AngularFireAuth, 
    public afData: AngularFireDatabase, public router: Router) {

     let transactionTemp = this.afData.list('transaction');
     this.getTransactionList = transactionTemp.valueChanges();
  }

}
dalemncy
  • 609
  • 8
  • 26

1 Answers1

0

You should simply use query with orderBy

let transactionTemp = this.db.list('/transaction', {
      query: {
        orderBy: 'amount',
        limitToLast: 100
      }
});
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396