user2948105 user2948105 - 2 months ago 12
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

You could use bracket notation.

$scope.items[$scope.attribute] = $scope.value;