0

I am trying to query an ordered list in ionic3 and Angularfire2.

By this query it show me the restaurants from lowest to highest rating but how can I query from high to low?

the query:

this.restaurantsRef = afDb.list('/restaurants', ref => ref.orderByChild('rating'));

And how can I do a multiple query? As the user wants to filter the restaurants on multiple conditions.

AngularFire version:

"angularfire2": "^5.0.0-rc.6",

The documentation says this:

// Order descending by numbers or strings
afs.collection('people', ref => ref.orderBy('age', 'desc') )
afs.collection('people', ref => ref.orderBy('name', 'desc') ) // reverse alphabetical

But when I try orderBy it returns me this error:

ref.orderBy is not a function

OrderBy seems not to exist on type Reference

Could someone help me out?

Sireini
  • 4,142
  • 12
  • 52
  • 91

1 Answers1

0

Okay I have found a solution, I wrote a pipe like this:

import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
  name: 'reverse'
})
export class ReversePipe implements PipeTransform {

  transform(value) {
      if (!value) return;

      return value.reverse();
    }
}

And then used it in the html like this:

 *ngFor="let restaurant of restaurantsList | async | reverse" 
Sireini
  • 4,142
  • 12
  • 52
  • 91