Skip to content

How to order by date? #283

@justme1

Description

@justme1

Hi,

This one must be really simple as everyone who uses Firebase must encounter this problem.

In my server I save items like this:
var db = firebase.database();
var ref = db.ref("users");
var userRef = ref.child("userA");
var newUserRef = userRef.push();
newUserRef.set({
Date : Date.now(),
Msg : 'test'
});

Now assuming I have 2 items in 'userA' I want to display the items in descending order so the last item that got 'pushed' will be the first to be displayed to the user.

I'm using:

    this.itemsFirebase = this.af.database.list('/users/userA');

And in the template:

     <li *ngFor="let itemFirebase of firebaseService.itemsFirebase | async">
                 <notification-item [item]="itemFirebase"></notification-item>
     </li>

How can I reverse the order so that the user will see the last item that was pushed as the first item in the ngFor?

I read about Querying List(https://github.com/angular/angularfire2/blob/master/docs/4-querying-lists.md) but I couldn't find what I was looking for.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions