In the following non-angularfire pseudo-code I would expect to have firebase generate a key for the new data being pushed in.
var ref = Firebase(...);
var newref = ref.push({"blah":"blah"});
var autoKey = newref.name();
I try to do the same thing through angularfire with a bound model but it just gives me errors about the object not having a push()
method, similar to this question. He got it working when the data type was an array.
How do I get the nice behaviour I've seen in regular Firebase (non-angularFire) with automatic keys for objects?
If you want to use an Object and have auto-generated keys, use the add
method on a angularFireCollection
. For example:
function ExampleController($scope, angularFireCollection) {
var url = 'https://angularFireExample.firebaseio-demo.com/';
$scope.examples = angularFireCollection(url);
$scope.addExample = function(ex) {
$scope.examples.add(ex);
};
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With