Praveen Praveen - 2 days ago 6
AngularJS Question

Angular JS ng-repeat not displaying values

I am making an REST call from angular to Spring . I am able to get the response back .When i am trying to populate the values in the view using ng-repeat , nothing is shown on the screen .

This is my Angular Code This code is inside the showhidecontroller

var resuls = $http.post('http://localhost:8080/aeservices/AddConfig', dataobj);
resuls.success(function(data, status, headers, config) {
$scope.dbresponse= data;
$scope.messagetest = $scope.dbresponse[0].messages;
alert($scope.messagetest);
console.log( $scope.messagetest);
console.log(data);

});


This is my Response i recieved from API

[{
"data12": null,
"name": null,
"errors": ["error data1", "error data2"],
"messages": ["Configuration has been Added successfully", "Configuration has been Added successfully"]
}]


This is my HTML

<table ng-controller="ShowHideController">
<tr ng-repeat="item in dbresponse[0].errors" >
<span><td align="left" class="validationMsg"><img src="images/red_bullet.gif" border="0" width="8" height="8" alt="">&nbsp
{{item}}
</td></span></tr>
</table>


I tried using ng-repeat by declaring myself an item like this $scope.items = ['one','two','three','four']. Even this is not showing up on the HTML.

Answer

Try using data.data,

Controller:

app.controller("listController", ["$scope", "$http",
  function($scope, $http) {
    $http.get('test.json').then(function(response) {
      $scope.dbresponse = response.data;
    });
  }
]);

HTML:

  <table ng-controller="listController">
      <tr ng-repeat="item in dbresponse[0].errors">
        <td align="left" class="validationMsg"><img src="images/red_bullet.gif" border="0" width="8" height="8" alt=""> {{item}}
        </td>
      </tr>
  </table>

DEMO

Comments