Reputation: 9517
So I want the key in my firebase database to be dynamically generated.
At the moment, I have something like this
whatever.$add({
title: $scope.formData.title
})
UPDATE: The whatever
is actually a $firebaseArray
, and yes, returns an id.
Actually, in the above example, I wanted to do something like:
whatever.$add({
$scope.formData.type: $scope.formData.title
})
I basically want the key set to something that'll come from a form. Any way?
Upvotes: 1
Views: 338
Reputation: 9389
I'm supposing that whatever
is actually a $firebaseArray
and if i'm right your $add
will always result in a new child with random id.
If you want to create a new child with a custom id you should be working with .child().set()
:
var ref = new Firebase(yourFirebaseUrl);
ref.child(customId).set({
type: $scope.formData.title
});
Update:
To have the $scope.formData.title
as the id you should do:
var ref = new Firebase(yourFirebaseUrl);
ref.child($scope.formData.title).set({
type: $scope.formData.title
anotherData: $scope.formData.anotherFormData
});
Upvotes: 1