1

I'm getting an array of data from server and going to update the $scope in angularJS.

The initial value is :

$scope.form = {};

I want to update dynamically like this:

$scope.form = {"firstname" : "Alex"};

both firstname and alex must update by an array like this:

sent.then(function(result) {
  angular.forEach(result.data.test, function(value, key){
    // ** something like this, but it doesn't work :
    var form_child = "{" + value.FieldName + ":" + value.FieldValue "}";
    $scope.form = form_child;
  });
});

How should I do line ** ?

2 Answers 2

1

Use array syntax :

$scope.form[value.FieldName] = value.FieldValue;
Sign up to request clarification or add additional context in comments.

Comments

0

in angular you don't have access to child scope, you only have access to parent's scopes.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.