'query' does not exist in type 'QueryFn' | angularfire2

余生长醉 提交于 2019-12-03 09:32:00
Orlandster

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

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

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

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

Mahbub Azad

You can try this code:

return this.db.list('/categories', ref => ref.orderByChild('name')).valueChanges();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!