Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the equivalent of firebaseRef.push() with angularfire?

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?

like image 989
Dave E Avatar asked May 13 '13 23:05

Dave E


1 Answers

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);
  };
}
like image 142
Anant Avatar answered Sep 28 '22 08:09

Anant