When is the $ asArray vs $ asObject method used in Angularfire?
The latest version of angularfire 1.0.0
uses the new $ firebaseArray and $ firebaseObject services, which replace $ asArray and $ asObject when accessing collections or objects.
If you are using the latest version, you must convert $ asObject and $ asArray to new services.
var arr = $firebase(new Firebase(URL)).$asArray;
var obj = $firebase(new Firebase(URL)).$asObject;
becomes
var arr = $firebaseArray(new Firebase(URL));
var obj = $firebaseObject(new Firebase(URL));
More information is available at AngularFire Documentation
source to share
You must use $asObject
for objects (hashes of key / value pairs) such a user profile, book description, or form data. Or, to quote the manual :
Objects are useful for storing key / value pairs and unique records that are not used as a collection.
You must use $asArray
for a collection, for example a list of users, books, or messages in a form.
In other words, if you iterate and use it in ng-repeat
, it is probably a collection. If you refer to properties by name, for example data.some_key
on it, it is probably an object.
source to share