1

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.

3 Answers 3

2

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

Sign up to request clarification or add additional context in comments.

8 Comments

How is this any different than what op has posted? (your edit makes more sense now)
@ForeignObject yes i was in the middle, hope its better now
Hey , you are doing the same thing i have done , May i know where i am going wrong
$scope.dbresponse = data.data;
I did the Same now as you suggested , but still its not coming up in the view
|
0

Please try this below code and don't declare variable resuls.

  $http.post('http://localhost:8080/aeservices/AddConfig', dataobj).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);

                });

7 Comments

I tried this and able to get the Alert, but my problem is i am not able to display it on the html
As you are making AJAX call in an variable doesn't return anything.
I have chnaged my code and tried the way you have mentioned, but still its not working . I hope there might be a problem with my controller/html part
Before trying ng-repeat. Just try $scope.test="preveen"; and display in html and let me know whether it displays praveen ?
No it is not getting displayed
|
0

The Problem that happened was i have declared my controller twice in the HTML

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.