0

I am making an Rest call from Angular JS. once i get the response from the API . I am planning to Populate Messages on the Front end using ng-repeat .This is my controller side call .

     $http({
          url: "http://localhost:8080/services/AddConfig", 
          method: "POST",
          data: dataobj,
          headers: {
                'Content-Type': 'application/json'
            }
         }).success(function(data, status, headers, config){
                responseData = data;
                $scope.dbresponse = responseData;
                console.log(responseData);
                console.log($scope.dbresponse[0].messages);
                console.log($scope.dbresponse[0].errors);
                if( $scope.dbresponse[0].messages[0] != null){
                    console.log("success message");

                    console.log("After Setting it");
                }else if ($scope.dbresponse[0].errors != null){
                    console.log("has errors throw validation message");
                }
         }).error(function(error){
                alert("Please Try again");
                });

This is My repsonse as seen on Console

    Object    
    errors:null
    messages:Array[1] 
           0:Added Successfully

What i want to do is access that message and populate on the front end .I'm using ng-repeat to do and its failing.

this is my HTML

     <table>
<tr ng-repeat="messages in dbresponse.messages">
<td align="left" class="validMsg"><img src="images/red_bullet.gif" border="0" width="8" height="8" alt="">&nbsp;{{messages}}</td></tr>
</table> 

1 Answer 1

1

In your API call response it seems your 'dbresponse' is an array:

console.log($scope.dbresponse[0].messages);

Whereas in your html you access it as a single object with properties:

<tr ng-repeat="messages in dbresponse.messages">

If your 'responseData' is an array you might want to treat it as such in your html. If it is not the case, please supply a bit more information on what the html looks like and what the '$scope' contains.

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

1 Comment

Hey Filipe ,It was a Typo . I am trying using ng-repeat like this only <tr ng-repeat="messages in dbresponse[0].messages" >.I am populating scope like this $scope.dbresponse = responseData; .The contents of the scope, i have posted it along with the Question

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.