I'm using firebase + angularfire for a project that involves multiple users editing data at the same time (which would make an object ideal) as well as the need to quickly sort and filter the data on the fly (ideal for an array). So, would it be better for me to:
1) use FirebaseObject and then use an angular toArray filter for sorting
2) use FirebaseArray and just make sure to use $add to ensure use of unique IDs (even storing the push ID as a property of the pushed object itself).
Currently, we are using the second option, which leads me to my second question: When I use $push, how can I return the ref.key() back to the controller? Modifying the example from the API guide:
var list = $firebaseArray(ref);
var addItem = function(itemDataObject) {
list.$add(itemDataObject).then(function(ref) {
var id = ref.key();
console.log("added record with id " + id);
list.$indexFor(id); // returns location in the array
});
};
How can I get that id variable to be returned when the addItem function is called? Even if I declare a variable outside the list.$add function and set the variable within the function, I get an undefined result.