1

It works now...

I GET array and stick name in input, then I change name in input and PUT it.

HTML

<form id="edit">
    <table>
        <tr>
            <th>Name: </th>
            <td>
                <input id="name" form="edit" type="text" ng-model="name" required>
            </td>
        </tr>
    </table>
    <button ng-click="edit()">Submit</button>
</form>

AngularJS

$scope.display = function()
{
    var connection = $http(
    {
        method: 'GET',
        url: 'http://localhost:8080/students?id=' + $scope.id
    })

    .then(function(response)
    {
        $scope.myArray = response.data;
        $scope.name = $scope.myArray[0].name;
    })
Harley
  • 1,305
  • 1
  • 13
  • 28

2 Answers2

0

You need to check the status_code on the response not on response.data:

    if (response.status == 200) 
    {
        success();
    } 
    else 
    {
        fail();
    }
2ps
  • 15,099
  • 2
  • 27
  • 47
  • Look at the code sample above. Don’t remove .data from the $scope.myResponse assignment, just for the if/then chec. – 2ps Oct 09 '16 at 06:24
  • I see the assignment doesn't achieve anything but it still likes response.data not response.status - I've updated the code in the post – Harley Oct 09 '16 at 06:33
0

You should check your $scope.name properly update in controller when you hit the button. your request might be fail because of your $scope.name not update in controller properly.

Haider Ali
  • 227
  • 3
  • 17
  • Your two way binding is not working properly. Please initialize `$scope.name = undefined`. right after `controller function` then check and let me know. – Haider Ali Oct 09 '16 at 06:53
  • still no luck, I'm testing inside and outside the table, outside the table works fine inside the table no luck – Harley Oct 09 '16 at 07:10
  • Then you just pass the `name` in your `ng-click="edit(name)"` and update your function in controller too like `$scope.edit = function(name)..` , `url: 'http://localhost:8080/students?name=' + name` it's surly work for you. – Haider Ali Oct 09 '16 at 07:15
  • @user3121518 you can check your question's answer here "http://stackoverflow.com/questions/12618342/ng-model-does-not-update-controller-value" here is discussion why is not working with $scope.var ... – Haider Ali Oct 09 '16 at 07:26