0

This function is used to update and save the data into the firebase database. It's not working properly as I put the breaking at the save function, control doesn't enter the function. The changed data is reflected in the html but not in the firebase database.

$scope.editFormSubmit = function(){ console.log("Updating record"); //Get ID var id = $scope.id; console.log(id); //Get Record var rec = $scope.records.$getRecord(id); console.log(rec); //Assign Values rec.fname = $scope.fname; rec.lname = $scope.lname; rec.mname = $scope.mname; rec.email = $scope.email; rec.company = $scope.company; rec.phone = $scope.phone; rec.city = $scope.city; rec.state = $scope.state; rec.zipCode = $scope.zipCode; rec.conId = $scope.conId; rec.DCN = $scope.DCN; rec.jobTitle = $scope.jobTitle; rec.pAddress = $scope.pAddress; rec.country = $scope.country; rec.name = $scope.name; // Save Record console.log("After assigning values"); console.log(rec); $scope.records.$save(rec).then(function(){ console.log("Updating values"); }); clearFields(); //hide the edit form $scope.editFormShow = false; $scope.msg = "Contact Update"; } 

1 Answer 1

1

Did you try

$scope.records.$save(rec).then(function(){ console.log("Updating values"); }, function(error) { console.log(error); }); 
Sign up to request clarification or add additional context in comments.

2 Comments

I changed the code now i am getting this error Error: Key mname was undefined. Cannot pass undefined in JSON. Use null instead. but i am before saving running this code for every field if ($scope.fname) { rec.fname = $scope.fname; } else { var fname = ""; }
i figured it out ...i was running this code if ($scope.fname) { rec.mname = $scope.mname; } else { var fname = ""; } here i was passing undefined i edited my code to this if ($scope.fname) { rec.mname = $scope.mname; } else { var fname = " "; } passing an empty string it worked.. thankyou for your help.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.