0

I have a project I am working on where I have a json array (that will later come from a web service)

and I am trying to use ng-repeat to load that data into a table. (I have done this before, this time it's just slipping paste me what I am missing)

I posted the code to github here: https://github.com/sheets/Sch

I'd love any help I am posting the code here as well:

<body ng-app="MyApp">
<div ng-controller="SchCtrl">

    <table class="table table-striped table-bordered">
        <thead>
        <th width="15%">Date and Time</th>
        <th width="50%">Provider</th>
        <th width="15%">Location</th>
        <th width="10%">Map</th>
        </thead>
        <tbody>
        <tr ng-repeat="appointment in appointments | orderBy:'startDatetime':true">
            {{appointments.startDatetime | date:'MM/dd/yyyy HH:mm'}}
            {{appointments.providerName}}
{{appointments.apptLocation}}</tr></tbody></table>


</div>
</body>

and app.js:

var app = angular.module("MyApp", []);

app.controller("SchCtrl", function($scope, $http) {
    $http.get('/appointments.json').
        success(function(data, status, headers, config) {
            $scope.appointments = data;
        }).
        error(function(data, status, headers, config) {
            // log error
        });
});
2
  • For one thing... you have no <td>. Commented Sep 3, 2014 at 16:41
  • Removed for debugging. Commented Sep 3, 2014 at 16:43

3 Answers 3

3

Try accessing appointment.startDatetime instead of appointments.startDatetime. Same for providerName and apptLocation. Basically remove the s in appointments.

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

Comments

2

You can take a look at this simple exaple
1. You need to wrap all your data in TD tags
2. To access your data - you need to do that like data.appointments
3. In ng-repeat you need to access every item in your appointments array - so that is appointment

Comments

2

Shouldn't it be

$scope.appointments = data.appointments

? And then you have to access

appointment.<field_name>

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.