0

What if I don't want to directly assign my collection like this:

$scope.items = angularFireCollection(ref);

Because I need to access the object in a callback once it's received:

angularFireCollection(ref, function(items) {
  angular.forEach(items, function(item){
    angular.forEach(item.tags, function(tag){
      $scope.allTags.push(tag);
    });    
  });
  $scope.items = items;
});

Does a callback method exist for the angularFireCollection service?

2 Answers 2

1

Yes there is, from the documentation on explicit binding:

angularFireCollection takes an optional second argument - a callback that will be invoked when the initial data has been loaded from the server. The callback will be provided with a Firebase snapshot as the only argument.

So you could call another function in the callback that will iterate over $scope.items directly to load the $scope.allTags array, or do something like you are now but use the snapshot instead (e.g. use the forEach() function).

Sign up to request clarification or add additional context in comments.

Comments

0

Use .val() as an extension of the object returned by the callback to access it's value.

$scope.items = angularFireCollection(ref, function(i){
    console.log(i.val());
});

JSFiddle

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.