PCas
PCas

Reputation: 3

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?

Upvotes: 0

Views: 63

Answers (1)

plong0
plong0

Reputation: 2188

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 );

Upvotes: 1

Related Questions