1

1) I have a input field as follows

<label>Size:</label>
<input type="text" ng-model="data.Size" ng-init="data.Size='10000000'" />

<label>Number:</label>
<input type="text" ng-model="data.Number" ng-init="data.Number='10'" />

As you can see, the size and number have been initialized with ng-init.

2) Now i have a ajax call to server posting this input parameters

var submitData = "=" + JSON.stringify(data);
$.ajax({
            type: "POST",
            url: serviceURL2,
            data: submitData
        }).then(function (response) {
            console.log(response.Info);

});

The response of this ajax function contains new values for Size and Number input field. console to response.Info gives this output in object form as shown below.

[Object]

0: Object

size:10000

number:5

Now, i need to pass this values to the input fields so that the values reflect the new values which we get by calling ajax call as shown above.

can someone please let me know how to bind these two and display it to the user

3
  • "=" + <-- why is there an equals before the data? Commented Jan 13, 2016 at 22:05
  • @epascarello- have tried other ways to stringify the data but didnt work for me. putting "=" works fine. dont know the actual reason why it has to be like that Commented Jan 13, 2016 at 22:13
  • But that makes zero sense. If it works, I have no idea why. Commented Jan 13, 2016 at 22:17

1 Answer 1

1

You don't need to use ng-init here, you only need to bind response object to $scope.data, Also you should use $.ajax

Code

var submitData = "=" + JSON.stringify(data);
      $http({
            type: "POST",
            url: serviceURL2,
            data: submitData
      }).then(function (response) {
            var data = response.data;
            console.log(data.Info);
            $scope.data = data.Info;
      });
}
Sign up to request clarification or add additional context in comments.

1 Comment

When i write $scope.data = data.Info, it refreshes the page and null values gets shown on those fields. any update on why it does this kind of behavior

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.