Search code examples
javascriptangularjsrestangular

restangular get full json response


I'm new to restangular and trying to integrate it in my app. Here is what i done so far:

 MyResource.getList(params).then((dt) ->
      console.log dt
    )

If I use $http.get then I get my full json object

{
 "param" : "a",
 "param2" : "b",
 "data": [
  {
    "id": 6,
    "name": "v1",
    "address": "some long address"
  },
  {
    "id": 8,
    "name": "vadsf",
    "address": "some long address again"
  },
  {
    "id": 13,
    "name": "asdf",
    "address": "another long address"
  }
 ]
}

but with restangular, I'm getting following:

[
 {
    "id": 6,
    "name": "v1",
    "address": "some long address"
 },
 {
    "id": 8,
    "name": "vadsf",
    "address": "some long address again"
 },
 {
    "id": 13,
    "name": "asdf",
    "address": "another long address"
 }
]

How I can get full json instead of only data array?


Solution

  • I sorted it out. In my app config

            RestangularProvider.addResponseInterceptor((data, operation) ->
                if operation is 'getList'
                  extractedData = data.data
                  if data.total then extractedData.param = data.param
                  if data.total then extractedData.param2 = data.param2
                  return extractedData
                else data
            )