I have attempted to access a child from a syncronized array after it has been added like so:
var postsRef = new Firebase("https://bragr.firebaseio.com/posts");
var ref = new Firebase("https://bragr.firebaseio.com");
var auth = $firebaseAuth(ref);
$scope.array.$loaded().then(function() {
// NEW POST IS ADDED:
postsRef.on('child_added', function(childSnapshot, prevChildKey) {
var index = $scope.posts.$indexFor(id);
var tmpPost = $scope.posts[index];
console.log(tmpPost); // LOGS -1
});
});
It seems that when a new Post is added, the index returns -1 which means that the item is not yet in the list. I assumed the child_added function was called when the child was added to said list. But it seems I am mistaken.
How can I ensure the Item is accessible from the list after it has been added? I am using Angular Fire, and I am attempting to update the view when a new Item is added by another user.