Sorry for the length of this but it\'s driving me a little bit crazy:
Let\'s say I want to get an item\'s \"title\" and \".priority\" key values when it loads.
F
As you've noted, your examples are a bit fragmented and there's also no example of your data structure to work from. So it's a bit hard to get a strong picture of what you're trying to accomplish. I'm going to make some assumptions below about all of these things and then offer a working example accordingly. If that doesn't answer the question, maybe it'll help us dig in and find the exact use case you're looking for.
Let's assume, for starters, that we have a list of users at kato.firebaseio.com/users, each of which is an object like so:
/users/:id/name
/users/:id/email
/users/:id/favorite_dessert
Now, let's assume I want to make those work with the following angularCode:
- {{user.name}} really likes {{user.favorite_dessert}}
In my controller, I could put something like this:
var fbRef = new Firebase('https://kato.firebaseio.com/users');
$scope.users = $firebase( fbRef );
Now they will automagically appear in my HTML code.
Now, let's assume that when one of these users is clicked, I want to get a two-way binding, which can be edited in a form like this:
Inside EditUserController
I could obtain the user as follows:
var fbRef = new Firebase('https://kato.firebaseio.com/users/'+user_id);
$firebase( fbRef ).$bind($scope, 'user');
Or I could use $child
like this (purely to demonstrate usage of $child, not necessary):
var fbRef = new Firebase('https://kato.firebaseio.com/users');
// $child gives a new $firebase object! not a ref to a hash key!
$firebase( fbRef ).$child( user_id ).$bind($scope, 'user');
If I wanted to access any of this data programmatically inside my controller, I could do it like so:
var fbRef = new Firebase('https://kato.firebaseio.com/users');
var usersRef = $firebase( fbRef );
var userId = 'kato';
usersRef.$on('loaded', function() {
if( usersRef.hasOwnProperty(userId) ) {
// note that we just grab it by key; not $child!
var userRecord = usersRef[userId];
console.log(userId + ' was found, name is ' + userRecord.name + ' and priority is ' + userRecord['$priority']);
}
});