how to set custom headers with a $resource action?

前端 未结 5 1618
谎友^
谎友^ 2020-12-03 04:37

with $http, we can do this:

var config = { headers: { \'something\': \'anything\' } };          
$http.get(\'url/to/json\', config)
    .success(function()          


        
5条回答
  •  无人及你
    2020-12-03 04:57

    headers for $resource is available since AngularJS 1.1.1. Make sure you have correct version used.

    The format is

    $resource('url/to/json', {}, {headers: { 'something': 'anything' }});
    

    [edit by zuma] The above doesn't seem right. The third parameter to $resource should be a different. This seems more correct to me:

    $resource('url/to/json', {}, {
        get: {
            method: 'GET',
            headers: { 'something': 'anything' }
        }
    });
    

提交回复
热议问题