3

Here's my code:

var userAuth;
var user = $resource('https://myservice.com/user/:id/', {id: '@_id'} ,{
    login: {
        method: 'POST',
        params: {
            id: 'login'
        },
        transformResponse: function(data) {
            data = angular.fromJson(data);
            userAuth = 'Kinvey '+data._kmd.authtoken;
            return data;
        }
    },
    current: {
        method: 'GET',
        params: {
            id: '_me'
        },
        headers: {
            'Authorization': userAuth
        }
    }
});

I want to be able to use the updated contents of the userAuth variable in the headers of the current endpoint of the resource, after it has been modified in the transformResponse of the login call. Is this even possible? If so, how?

EDIT: I am using Angular version 1.1.3 - this question is about changing the headers in the resource once they have been set, not settings them initially. Thanks

4

1 に答える 1