0

I'm trying to add data to existing data within Firebase using AngularFire my data currently looks like this, very simple list of clients:

clients
--Firebase UID
----client: Client1
--Firebase UID
----client: Client2
--Firebase UID
----client: Client3

But I want to be able to add under the client sections such as team with a list of team members and some of their details. eg

--Firebase UID
----client: Client1
------team: {Bob: {email: address, position: developer}, Peter: {email: address, position: developer}}
--Firebase UID
----client: Client2
--Firebase UID
----client: Client3 ------team: {Bob: {email: address, position: developer}}

This is my current code:

var firebaseURL = 'https://<myfirebase>.firebaseio.com/clients';
$scope.clients.team = {Bob: {email: address, position: developer}, Peter: {email: address, position: developer}};
$scope.clients.$save(Client1);

All I keep getting is the following error:

Error: Firebase.set failed: First argument contains undefined at Error (native)

I've looked at the AngularFire documentation here https://www.firebase.com/docs/angular/reference.html#save-key and believe I've followed it correctly.

1 Answer 1

1

Note that the argument passed to $save should be a string, pointing to the key name that you want to save.

Secondly, when you define new properties on the scope object, they'll need to be at the right path (you're missing the UID of the client when saving the team).

Thirdly, if any of the pieces of data resolves to undefined the data will not be saved. Ensure that everything under the team is either a variable that has a value, or is a string.

var firebaseURL = 'https://<myfirebase>.firebaseio.com/clients';
$scope.clients = $firebase(firebaseURL);
...
$scope.clients[clientUid].team = {
  "Bob": {email: "some address", position: "developer"}
};
$scope.client.$save(clientUid);
Sign up to request clarification or add additional context in comments.

2 Comments

But how do I go about getting the clientUid? Thats another stumbling block. I cant get the Id of each object. How would I go about getting this?
That depends on how you are adding them. If you are using $add, you can get the key name of the newly added data via ref.name() where ref is passed upon resolution of the promise returned by $add.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.