Devesh Agrawal
Devesh Agrawal

Reputation: 9212

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 = brand.id;
    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??

Upvotes: 0

Views: 149

Answers (1)

Odonno
Odonno

Reputation: 419

According to https://groups.google.com/forum/#!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.

Upvotes: 1

Related Questions