PCas PCas - 1 month ago 14
AngularJS Question

Set a scope in AngularJS as a key on Firebase

There is a way to set a

$scope
variable as a key on Firease?

I've tried this:

xxx.$add({
$scope.xxxx.key: {
name: $scope.xxx.name,
age: $scope.xxx.age,
email: $scope.xxx.email,
}
});


But isn't work, there is way to do that?

Answer

You can build objects with dynamic property names in javascript like this:

var newEntry = {};
newEntry[$scope.xxxx.key] = {
    name: $scope.xxx.name,
    age: $scope.xxx.age,
    email: $scope.xxx.email,
};
xxx.$add( newEntry );