0

I try to sort data depending on the timestamp of the data set. To do so I created this service:

import { Injectable } from '@angular/core';
import {AngularFirestore} from 'angularfire2/firestore';

@Injectable({
  providedIn: 'root'
}) export class BlogService {
  constructor(private afs: AngularFirestore) { }

  getStudents() {
    return this.afs.collection('Blogs', ref => ref.orderBy('ts')).valueChanges();
  }
}

At the moment I receive the data in a ascending order but i want to receive it in a descending order, which means the newest value first.

1 Answer 1

1

This sould work as expected,

import {orderBy} from "lodash";

getStudents(){
   return this.afs.collection('Blogs', ref => orderBy(ref, ['ts'], ['desc'])).valueChanges();
 }
Sign up to request clarification or add additional context in comments.

2 Comments

I was about write this ans :)
doesnt work unfortunately i receive this error: ERROR in src/app/blog.service.ts(14,32): error TS2345: Argument of type '"Blogs"' is not assignable to parameter of type 'CollectionReference'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.