'query' does not exist in type 'QueryF

2019-04-02 09:52发布

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

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

chat.service.ts

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

3条回答
相关推荐>>
2楼-- · 2019-04-02 10:13

QueryFn must return a firebase.database.Query, not void. You can code the query like this one, for more clear:

getMessages(): Observable<ChatMessage[]> {
    return this.db.list('/messages', ref => {
      let q = ref.limitTolast(25).orderByKey(true);
      return q;
    });
  }
查看更多
姐就是有狂的资本
3楼-- · 2019-04-02 10:20

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

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 => {
      ref.limitTolast(25).orderByKey(true)
    });
  }

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

查看更多
冷血范
4楼-- · 2019-04-02 10:26

This will work perfectly. Tried by me

getMessages(): Observable<ChatMessage[]> {
    return this.db.list('/messages', ref => 
      let q = ref.limitTolast(25).orderByKey(true);
      return q;
    );
  }

for more information related to queries goto this link: https://github.com/angular/angularfire2/blob/master/docs/rtdb/querying-lists.md

查看更多
登录 后发表回答