Firebase.push failed: first argument contains an invalid key ($$hashKey)

angularjs, firebase

Solution

EDIT: As Anant points out in the comments, in the latest stable version of Angular (1.0.7 atm), you can use `angular.copy(obj)` to remove `$$hashkey` attributes.

Like Michael said, the '$' in '$$hashKey' is the issue. Angular creates the `$$hashKey` properties behind the scenes (see more here: https://groups.google.com/forum/#!topic/angular/pI0IgNHKjxw). I've gotten around this issue by doing something like `myRef.push(angular.fromJson(angular.toJson(myAngularObject)))`.

Problem

I recently started learning AngularJS+Firebase. I'm trying to write in my firebase an object like this: ``` { title: "Personal Information", say: [ [{ "eng": "What's", "ukr": "Що є" }, { "eng": "your", "ukr": "твоє" }, { "eng": "surname?", "ukr": "прізвище?" }], [{ "eng": "Smith", "ukr": "Сміт" }], [{ "eng": "What's", "ukr": "Що є" }, { "eng": "your", "ukr": "твоє" }, { "eng": "first", "ukr": "перше" }, { "eng": "name?", "ukr": "ім'я?(не фамілія)" }] ] } ``` with line: ``` lessondata.add($scope.topic); ``` where 'lessondata' is service created with angularFireCollection() and $scope.topic - object bound to my UI. But got the following error: Firebase.push failed: first argument contains an invalid key ($$hashKey) in property 'say.0.0'. Keys must be non-empty strings and can't contain ".", "#", "$", "/", "[", or "]" As I understood Firebase do not allow to use 0 as a key even if it's a key in an attached array for which zero key is natural. So should I change my object structure in some hardcoded instance or I miss something? Thanks in advance!

Original source

Related problems