简体   繁体   English

查询可观察和angularfire2

[英]query observable and angularfire2

i'm wondering how can i use angularfire2 to query data an get the list of the queried data and then observer next the data to be able to subscribe to it and pass it into an ngFor loop, for example , how can i transform this sample code below to use angularfire2 我想知道如何使用angularfire2查询数据并获取查询到的数据列表,然后观察者接下来可以将数据订阅并传递到ngFor循环中,例如,如何转换此样本下面的代码使用angularfire2

load() {
  const messagesObservable = new BehaviorSubject<MessageThread[]>(null)
  this.rootRef.child("users").child(this.currentUserid).child("rooms").on("child_added", snapshot => {
    key = snapshot.key()
    this.rootRef.child("messages").orderByKey().equalTo(key).on("value", snapshot => {
      const data = snapshot.val()
      const Messages = Object.keys(data).map(id => new MessageThread(id))
      MessageThread.next(Messages)
    })
  })
  return Messages
}

I would try something like this: 我会尝试这样的事情:

constructor(private af: AngularFire) {
}

load() {
  return this.af.list(this.rootRef.child("messages")
                   .orderByKey().equalTo(key));
}

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

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