I have started using latest angular 13 with angularfire 7 and firebase 9 and my code to query data is like below:
import { Database, objectVal, ref, listVal, update } from '@angular/fire/database';
constructor(public db: Database) { }
return new Promise((resolve, reject) => {
const doc = ref(this.db, "/users/" + userKey + "/cards");
listVal(doc).subscribe(
(res:any) => {
resolve(res)
},
err => {
console.log(err)
reject(err)
}
)}
)
I want to pass a orderBy query to it like orderByChild('_date') and could not find in the docs. The docs referred is https://github.com/angular/angularfire/blob/master/samples/modular/src/app/database/database.component.ts
I see listVal accepting the Query param but don't see how to do it.
here is how to do it
import { Database, objectVal, ref, listVal, update, query, orderByChild } from '@angular/fire/database';
constructor(public db: Database) { }
return new Promise((resolve, reject) => {
const doc = ref(this.db, "/users/" + userKey + "/cards");
const qry = query(doc, orderByChild('_date'))
listVal(qry).subscribe(
(res:any) => {
resolve(res)
},
err => {
console.log(err)
reject(err)
}
)}
)