0

I am new to angular and am trying to load table data from controller.Data is coming but its not displaying in table.What went wrong here?

<script>
    var app=angular
                .module("intranet_App", [])
                .controller('myCtrl', function ($scope, $http) {
                    $http.post("/Admin/getRolesList")
                    .then(function (response) {
                        console.log(response)
                        $scope.List= response.data;
                       console.log(List)
                    });
                })
</script>

Here /Admin/getRolesList is my controller name and path.

html:

          <tbody >
                <tr ng-repeat="x in List">
                    <td>{{List.Id}}</td>
                    <td>{{List.name}}</td>
                </tr>
            </tbody>

This is my response format:

enter image description here

2 Answers 2

1

You have getting the values from like Array.value, it should like Array[0].value. So Use x.Id instead of List.Id,

             <tbody>
                <tr ng-repeat="x in List">
                    <td>{{x.Id}}</td>
                    <td>{{x.name}}</td>
                </tr>
            </tbody>
Sign up to request clarification or add additional context in comments.

2 Comments

thanks man.working :-) one doubt, what is x here ?we can use anything instead of x right? If I want 1,2,3... in the place of id means ..how to use for loop here?
here, x is object name of the expression. more details : w3schools.com/angular/ng_ng-repeat.asp
1
  //use track by for performance optimization..
         <tbody>
            <tr ng-repeat="x in List track by $index">
                <td>{{x.Id}}</td>
                <td>{{x.name}}</td>
            </tr>
        </tbody>

1 Comment

Please refer this for more understanding docs.angularjs.org/error/ngRepeat/dupes

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.