0

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??

4
  • I think you have an invalid key/id. Is $$hashKey your brand id ? If it is, FIrebase does not accept '$' in keys. Commented Aug 14, 2016 at 9:29
  • @Odonno, My brand id String like 23, 34, 45 etc Commented Aug 14, 2016 at 10:02
  • 1
    According to 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. Commented Aug 14, 2016 at 10:28
  • Thanks. Its working now. Please post your answer, so i will accept that. Commented Aug 14, 2016 at 10:36

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.