'query' 在类型 'QueryFn' 中不存在 |角火2 [英] 'query' does not exist in type 'QueryFn' | angularfire2

查看:30
本文介绍了'query' 在类型 'QueryFn' 中不存在 |角火2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

'{ 类型的参数 query: { limitTolast: number;orderByKey:布尔值;};}' 不能分配给 'QueryFn' 类型的参数.对象字面量只能指定已知的属性,而 'query' 不存在于类型 'QueryFn' 中.

Argument of type '{ query: { limitTolast: number; orderByKey: boolean; }; }' is not assignable to parameter of type 'QueryFn'.Object literal may only specify known properties, and 'query' does not exist in type 'QueryFn'.

package.json

package.json

"angularfire2": "^5.0.0-rc.3",
"firebase": "^4.5.1",

chat.service.ts

chat.service.ts

getMessages(): FirebaseListObservable<ChatMessage[]> {
    return this.db.list('messages', {
      query: { limitTolast : 25, orderByKey: true}
    });
  }

推荐答案

它不起作用,因为 AngularFire 期望将函数作为第二个参数传递.

It's not working, because AngularFire expects a function to be passed as a second argument.

我认为您的示例在测试版中是正确的做法.(不是 100% 确定)

I think your example was the right way to go during the beta version. (not 100% sure)

您已通过以下方式使用它:

You have use it the following way:

// make sure to provide a child in the orderByChild call
getMessages(): Observable<ChatMessage[]> {
    return this.db.list('/messages', ref => {
      return ref.limitTolast(25).orderByKey(true)
    });
  }

在此处了解有关查询列表的更多信息:https://github.com/angular/angularfire2/blob/master/docs/rtdb/querying-lists.md

Learn more about querying lists here: https://github.com/angular/angularfire2/blob/master/docs/rtdb/querying-lists.md

这篇关于'query' 在类型 'QueryFn' 中不存在 |角火2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆