Accessing Headers when extending ng.resource.IResourceClass

35 Views Asked by At

If I extend the IResourceClass like so:

interface UserResource extends ng.resource.IResourceClass<UserResource> {}

Then when I try to access the headers when I query:

userResource.query({})
    .$promise
    .then(
        (data, headers) => {
            vm.headers = JSON.parse(headers("X-Pagination"))
            vm.users = data;
        }
    )

it will give a compile error because the type definitions don't provide for the additional headers parameter. How do I resolve this?

1

There are 1 best solutions below

0
georgeawg On BEST ANSWER

The headers function is exposed as the second argument of the optional success callback:

vm.users = userResource.query({}, successCB)

function successCB (data, headers) {
    vm.headers = JSON.parse(headers("X-Pagination"))
}

For more information, see