angularjstypescriptngresource

Accessing Headers when extending ng.resource.IResourceClass


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?


Solution

  • 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