Pregunta

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.

¿Fue útil?

Solución

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);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top