Devesh Agrawal Devesh Agrawal - 2 months ago 10
AngularJS Question

Not able to update firebase realtime database in angularjs (web)

This is my code to update a record in firebase.

$scope.EditBrand = function(brand) {
var key =;
var fredNameRef = firebase.database().ref('all-brands/' + key);

fredNameRef.set(brand, function(error) {
if (error) {
alert ('some error')
} else {
alert ('updated')

I checked the key, and its coming correct.

But when calling this function this is the error.

angular.js:12477Error: Firebase.update failed: First argument contains an invalid key ($$hashKey) in path /$$hashKey. Keys must be non-empty strings and can't contain ".", "#", "$", "/", "[", or "]"
at Error (native)

What is wrong with my code or logic??


According to!topic/angular/pI0IgNHKjxw, you should create a temporary object to avoid fields generated by angular. So, add this line in your method : var brandObject = angular.fromJson(angular.toJson(brand)); and use brandObject in the rest of the method.