Angular.js REST client

4,158 views
Skip to first unread message

Trương Hoàng Dũng

unread,
May 23, 2012, 4:41:31 AM5/23/12
to ang...@googlegroups.com
Hi everyone.
I have a question. I'm trying to get the courses from a REST server. I'm using controller like this:


function ListCtrl($scope, $http) {
        $http.get('https://canvas.instructure.com/api/v1/courses?access_token=<access_token>').success(function(data) {
    $scope.courses = data;
        });
}

The template is like this:


<tr ng-repeat="course in courses">
<td><a href="{{course.id}}" target="_blank">{{course.name}}</a></td>
<td>{{course.course_code}}</td>
</tr>

But the codes seem don't work.

May i make any mistake here ?
Thank you for reading.

Johan

unread,
May 25, 2012, 5:41:48 PM5/25/12
to ang...@googlegroups.com
I would use a service. Check out $resource - see the tutorial:


and API docs

randy...@google.com

unread,
May 27, 2012, 12:26:39 AM5/27/12
to ang...@googlegroups.com

nxqd....@gmail.com

unread,
Dec 7, 2012, 7:07:15 AM12/7/12
to ang...@googlegroups.com
Hi Dũng, 
have you figured out how to make it work ? 

Pascal Precht

unread,
Dec 8, 2012, 8:23:24 AM12/8/12
to ang...@googlegroups.com
"But the codes seem don't work."

What about the an error message? :)

Marit

unread,
Dec 8, 2012, 11:43:44 AM12/8/12
to ang...@googlegroups.com
Are you sure that you are looping over an array in your ng-repeat? It could be that courses is objects and not a collection of objects.
Try to  console.log(data) right after the http request as see what you get.

If its not a collection of objects (an array of objects) then ng-repeat will not work.
Check out the documentation:

Good luck!
Reply all
Reply to author
Forward
0 new messages