0
votes

I have below code to query the index from users node then pass the index to todos node to get the data I want but it only watching when a child is added so when a child is removed in the index it doesn't update the view.

I have no idea how to get the object key if I use value in the index node. Any idea? or any better way to query mastered data using angularFire?

FirebaseRef.$child(user.uid).$on('child_added', function(a) {
 FirebaseRef.$child('todos/' + a.snapshot.name).$on('value', function(b) {
   $scope.todoList[a.snapshot.name] = b.snapshot;
 });
});
1
What is FirebaseRef? A Firebase instance or a $firebase/angularFire object? If it's a Firebase object, use .child instead of .$child. Assuming it's a $firebase instance, then it already contains all the contents of todos/. What is the use case we're trying to solve here? It looks like this could be resolved in a simpler manner. - Kato

1 Answers

0
votes

try the following (not tested).

FirebaseRef.$child(user.uid).$on('child_added', function(a) {
 FirebaseRef.$child('todos/' + a.name()).$on('value', function(b) {
   $scope.todoList[a.name()] = b.snapshot;
 });
});

You shouldn't need 'snapshot' in your reference eg a.snapshot.name, you should just reference the object returned in your callback function