in

Getting DESC order with Angular2 and Firebase

I never thought this would be an issue… But I found that this simple need to get data from a db in DESC order was not “out of the box” with Firebase.

One comment on a Github question on this subject worked for me.  It’s one line of code and it simply works… way better than other more complex solutions.

Basically, you take your Observable, such as the one below:

this.posts = this.af.database.list('/posts') as FirebaseListObservable<Post[]>;

You can modify it with a map that runs a reverse method on it:

this.posts = this.af.database.list('/posts').map( (arr) => {return arr.reverse();}) as FirebaseListObservable<Post[]>;

What do you think?

0 points
Upvote Downvote

Total votes: 0

Upvotes: 0

Upvotes percentage: 0.000000%

Downvotes: 0

Downvotes percentage: 0.000000%

Written by Admin

I work for a Telecom company writing and testing software. My passion for writing code is expressed through this blog. It's my hope that it gives hope to any and all who are self-taught.

Comments

Leave a Reply

Loading…

Routing in Angular2

Heart Rate Tracking with Angular2 & Fitbit