Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the key name on an array in Angularfire

I am creating arrays using Angularfire but I am unable to set the key name. Firebase is automatically giving me a cryptic key (eg Jm9vLy8Lye-KS35KsmL) but I would like to set it myself to something more meaningful. It is unclear how I do this in Angularfire. I am using the $add method on $firebaseArray:

var firebaseRef = new Firebase("https://firebase_location"); 
$scope.messages = $firebaseArray(firebaseRef);

$scope.messages.$add( 
  {
    FirstName: patient.FirstName, 
    LastName: patient.LastName
  }
).then(function(firebaseRef) {
  var id = firebaseRef.key();
});

The data is stored fine and I can see it on my dashboard. However, id is always a cryptic firebase value. I would love to be able to set it myself to something meaningful. In my case the individual patient's ID would be meaningful...

Any thoughts?

Thank you!

like image 504
JohnK Avatar asked Apr 05 '15 19:04

JohnK


1 Answers

Thanks for the response.

I found that the child function will do what I need. I first specify the child and then set it.

var patient_child = firebaseScreenRef.child(patient.PatientId); 
      patient_child.set(
        { 
            FirstName: patient.FirstName, 
            LastName: patient.LastName, 
        });
like image 181
JohnK Avatar answered Nov 15 '22 21:11

JohnK