user2948105 user2948105 - 1 year ago 83
JSON Question

angular add/update json object from user input both attribute and value

I am able to get both attribute name and value from user input

{{attribute}} and {{value}}

how do i add these to an existing json object

$scope.items ={
name: peter,
age: 16,
{{attribute}}: {{value}}

Answer Source

You could use bracket notation.

$scope.items[$scope.attribute] = $scope.value;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download