I am new to angular and currently creating a project using Angular2 and Firebase.
I want to be able to sort my database in date created order. However, I am unsure on how I could achieve this. I looked up articles and seen their implementations. But I do not know how to implement this to my project.
Here is my code that deals with querying. My Firebase database just has title, content and date(I type the date manually).
posts: FirebaseListObservable<any>;
constructor(public navCtrl: NavController, public alertCtrl:AlertController, angFire: AngularFire) {
this.posts= angFire.database.list('/Post',{
query:{
orderByChild: "date"
}
});
Any help would be great, thankyou.
JSON here
{`"Post" : {
"-KYsuclduIKOVi6VXGmn" : {
"content" : "text goes here",
"date" : "12/12/16",
"title" : "Title"
}
} }
So all I had to do was add the
firebase.database.ServerValue.TIMESTAMP
to the date. This adds the timestamp to my firebase database.