首页 > 解决方案 > 升序行中的角度排序数据

问题描述

我尝试根据数据集的时间戳对数据进行排序。为此,我创建了此服务:

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();
  }
}

目前我按升序接收数据,但我想按降序接收数据,这意味着最新的值在前。

标签: angulargoogle-cloud-firestore

解决方案


这可以按预期工作,

import {orderBy} from "lodash";

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

推荐阅读