John Carson John Carson - 2 years ago 68
Javascript Question

How do I use $save() in Firebase' Angular-Fire to Update Object Property Values

I have the code below:

var FBref = new Firebase('');
var peopleObject = $firebaseArray(FBref);

var person = {


I use the code above to add new records of employees successfully.

I need to update the John's phone number to 111-111-111. But the code below doesn't work.

var person = {
"phone":"111-111-111" //New phone number


Someone advice

Answer Source

Currently you are trying to save whole object, which wouldn't work.

Retrieve old record first by getting record from db first & then update that record. Thereafter save that object using $save method.

//if update action is happening is similar session you can get unique by below code
var someRecordKey; 
peopleObject.$add(person).then(function(ref) { 
    //get record id of new person 
    someRecordKey = ref.key(); 

// get record by unique key
var person = peopleObject.$getRecord(someRecordKey);
// change a message and save it = "111-111-111";
peopleObject.$save(person).then(function() {
    // data has been saved to our database
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download