I saw this post on Firebase\'s blog explaining the best way to create relational data objects using their platform. I\'m struggling to translate these concepts to AngularFire,
Great question!
You do need access to the unique IDs, and we recently added a feature that will give you access to it via angularFireCollection
: https://github.com/firebase/angularFire/pull/26.
If you're using the implicit sync method (angularFire
), then you already have access to the keys as long as you specify the 4th argument that will set the type of the collection to 'Object':
function MyController($scope, angularFire) {
var url = 'https://awesome.firebaseio-demo.com/comments';
var promise = angularFire(url, $scope, 'comments', {});
promise.then(function() {
var id = '-lw2NDTiZMFvzEWmSnYn';
console.log($scope.comments[id]);
});
}
Hope this helps!
Yes you can access the ID! Use the code below!
var chru;
var ref = new Firebase("https://myapp.firebaseio.com/users/");
var sync = $firebase(ref);
var users= syncSelect.$asArray();
$scope.users= users;
users.$loaded().then(function() {
chru = users.length;
});
$scope.specificIdOnSelect = function() {
var jj;
for (jj = 0; jj < chru; jj++) {
var keyer = users.$keyAt(jj);
var rec = users.$getRecord(keyer);
if ($scope.userSelected== rec.name) {
alert("Unique Key of " + $scope.users+ " is " + users.$keyAt(jj));
}
}
};
$scope.allIds = function() {
var jj;
for (jj = 0; jj < chru; jj++) {
var keyer = users.$keyAt(jj);
var rec = users.$getRecord(keyer);
alert("Unique Key of " + $scope.users+ " is " + users.$keyAt(jj));
}
};