Search code examples
javascriptangularjsrestangular

angularjs restangular not getting data


I am trying to get restangular working. In my API (with the end point /user) I get this json response:

{
"error": false,
"response": {
    "totalcount": 2,
    "records": [{
        "id": "1",
        "groupId": "14",
        "fullName": "Mark Smith ",
    }, {
        "id": "2",
        "groupId": "14",
        "fullName": "Joe Andrews",
    }]
}

}

I am using this in my service:

$scope.projects = Restangular.all('user').getList();
console.log($scope.projects);

This is the html:

 <li ng-repeat="project in projects>  
     {{project.groupId}} {{project.fullName}} 
</li>

I am not getting any data.

How can I access the data in the response:{totalcount:2, records: [{...}] and the data in the records:[{...}]?

My kung-fu is not enough to make it work.

Any ideas on what am I doing wrong?


Solution

  • It looks like you have your actual response wrapped. In that case you'll want to look at this part of the documentation: Restangular Wrapped Response. You'll need to use the addResponseInterceptor to make sure it returns the right data.