简体   繁体   English

在 angularfire 7 中使用带有查询参数的 listVal 和 angular 13

[英]using listVal with query parameters in angularfire 7 with angular 13

I have started using latest angular 13 with angularfire 7 and firebase 9 and my code to query data is like below:我已经开始使用最新的 angular 13 和 angularfire 7 和 firebase 9 我查询数据的代码如下:

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.我想像 orderByChild('_date') 一样将 orderBy 查询传递给它,但在文档中找不到。 The docs referred is https://github.com/angular/angularfire/blob/master/samples/modular/src/app/database/database.component.ts参考的文档是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.我看到 listVal 接受 Query 参数,但不知道该怎么做。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM