Firebase Angularfire2 - listening to the requested list

I am wondering if the child_added event can be used with the requested lists. For instance:

this.curUserPosts = this.af.database.list('/posts', {
    query: {
      orderByChild: 'user/id',
      equalTo: id
    }
  }).$ref.on("child_added", (child) => {
     console.log(child);
  });

I am interested in the following: Will it even work. Will it only start correctly when the added child matches the request. How good he is.

And also, what is the preferred way to handle such requested lists in firebase?

+4
source share
2 answers

No, that will not work; he will not have a request.

ref$ FirebaseListObservable ref, . ( ref $ref):

return new FirebaseListObservable(ref, subscriber => {
  ...
  let queried: firebase.database.Query = ref;
  if (query.orderByChild) {
    queried = queried.orderByChild(query.orderByChild);
  } else if (query.orderByKey) {
    queried = queried.orderByKey();
  } else if (query.orderByPriority) {
    queried = queried.orderByPriority();
  } else if (query.orderByValue) {
    queried = queried.orderByValue();
  }

, child_added , :

this.curUserPosts = this.af.database.list('/posts', {
  query: {
    orderByChild: 'user/id',
    equalTo: id
  }
});
this.curUserPosts.$ref
  .orderByChild('user/id')
  .equalTo(id)
  .on("child_added", (child) => {
     console.log(child);
  });

, , on $ref, this.curUserPosts , ; , on.

+3

, .

child_added , , child_added, , .

-1

Source: https://habr.com/ru/post/1667147/


All Articles