1

i am new in angular programming,

i want to bind json data that i get from webservice to the html table,

here is my code :

<!DOCTYPE html>
<html>
<head>
    <title>LIST OF USER Sample</title>
    <script src="../Scripts/angular.min.js"></script>
    <script src="../Scripts/module.js"></script>
    <script>

        function PeopleCtrl($scope, $http) {

            $scope.people = [];

            $scope.loadPeople = function () {

                var httpRequest = $http
                    ({
                        method: 'GET',
                        url: 'http://10.17.44.236:9090/MobileBootcamp.svc/getalluseravailability'

                    })
                    .success(function (data, status) {
                        debugger;
                        $scope.people = data;

                    });


            };
            $scope.loadPeople();
        }

    </script>
</head>
<body>
    <div ng-app="app">
        <div ng-controller="PeopleCtrl" ng-init="loadPeople()">
            <table>
                <tr>
                    <th>Id</th>
                    <th>Availibility</th>
                </tr>
                <tr ng-repeat="x in people.Datalist[0]">
                    <td>{{x.UserID}}</td>
                    <td>{{x.Availability}}</td>
                </tr>
                <tr>
                    <td>{{people.DataList[0].UserID}}</td>
                    <td>{{people.DataList[0].Availability}}</td>
                </tr>
                <tr>
                    <td>{{people.DataList[1].UserID}}</td>
                    <td>{{people.DataList[1].Availability}}</td>
                </tr>

            </table>
        </div>
    </div>


    <script src="cordova.js"></script>
    <script src="js/platformOverrides.js"></script>
    <script src="js/index.js"></script>
</body>
</html>

and this is the json from the web service

{"Status":true,"Message":"","Data":null,"DataList":[{"ChangeBy":"Admin","ChangeDate":"\/Date(1439437580137+0700)\/","ChangeNo":2,"CreateBy":"Admin","CreateDate":"\/Date(1439437580137+0700)\/","Availability":true,"LastCheckIn":"\/Date(1439437645420+0700)\/","UserID":"Admin"},{"ChangeBy":"ITK_ABD","ChangeDate":"\/Date(1439398800000+0700)\/","ChangeNo":1,"CreateBy":"ITK_ABD","CreateDate":"\/Date(1439398800000+0700)\/","Availability":false,"LastCheckIn":"\/Date(1439398800000+0700)\/","UserID":"ITK_ABD"}]}

i already try the "ng-repeat" but it didnt work,

the data is like Data --> DataList--> [0] --> userid,availability,etc...

thx in advance

2
  • <tr ng-repeat="x in people.Datalist[0]"> it should be <tr ng-repeat="x in people.DataList"> Commented Aug 13, 2015 at 10:06
  • is your http request viable? i followed it and go not available Commented Aug 13, 2015 at 10:07

4 Answers 4

2

You don't need the [0]. Your ng-repeat is here to get all elements of the list. You just have to give your list, not the index and angular will do the job.

<tr ng-repeat="x in people.DataList">
Sign up to request clarification or add additional context in comments.

1 Comment

Typo error. its people.DataList not people.Datalist
1

Do as following -

<tr ng-repeat="x in people.Datalist">
    <td>{{x.UserID}}</td>
    <td>{{x.Availability}}</td>
</tr>

as you have array of objects in Datalist, you should iterate DataList instead of DataList[0]

Comments

0

No need for the [0]. we don't want to loop through your first object, So just people.DataList will do the job. It will loop through all objects inside that array .

           <tr ng-repeat="x in people.DataList">
                <td>{{x.UserID}}</td>
                <td>{{x.Availability}}</td>
            </tr>

Comments

0

You are trying to repeat object here:

<tr ng-repeat="x in people.Datalist[0]">

You can repeat only on Array data type. So you must do this like that:

<tr ng-repeat="x in people.Datalist">

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.