user7397787
user7397787

Reputation: 1470

Get table data using $http in angular

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

Upvotes: 0

Views: 506

Answers (2)

Nainish Modi
Nainish Modi

Reputation: 488

  //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>

Upvotes: 1

Ramesh Rajendran
Ramesh Rajendran

Reputation: 38683

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>

Upvotes: 1

Related Questions