-1

I have an JSON object which I show in the html using ng-repeat. But when I make changes to the value in the html and try to print it again, it does not get reflected in the actual object.

This is my html snippet :

        <tbody>
            <tr ng-repeat="(key,value) in object">
                <td>{{key}}</td>
                <td><input type="text" ng-model="value">{{value}}</input></td>
            </tr>
        </tbody>
        <a href="">
             <button ng-click="printer()" class="btn btn-md btn-primary">Submit</button>
        </a>

This is my controller:

MyService.getObject(objectName).then(function(response) {
        console.log(response);
        $scope.object = response;
    });

    $scope.printer = function() {
        console.log("inside printer function");
        console.log("object is ===" + JSON.stringify($scope.object));
    }

Here MyService has an http get which returns a JSON object which I assign to$scope.object. I can view the object without any problems but when I change it and print it, I am not able to see the changes I made. There is a Submit button in my html which calls the printer function. After changing the value in my page, and clicking on submit, I am not able to see the changes.

<td><input type="text" ng-model="value">{{value}}</input></td> 

^^ here I have printed the value next to the text field. Any change I make to the text field also changes the value which means it works. But it does not get updated in the $scope

v1shnu
  • 2,211
  • 8
  • 39
  • 68

1 Answers1

2

I think

<td><input type="text" ng-model="value">{{value}}</input></td> 

should be:

 <td><input type="text" ng-model="object[key]">{{value}}</input></td> 

model value doesn't exist in your controller.

biancamihai
  • 961
  • 6
  • 14