如何设置自定义页眉以$资源行动?

如何设置自定义页眉以$资源行动?

问题描述:

与HTTP $,我们可以这样做:

with $http, we can do this:

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

我想这样做同样以$资源引用(不工作):

i would like to do the same with a $resource reference (not working):

var config = { headers: { 'something': 'anything' } };
MyResource.get( 
    config,
    function() { // success
        // do something…
    }
); 

通过声明如下相应的服务:

with the corresponding service declared like this :

.factory('MyResource', function($resource){
    return $resource('url/to/json');
})

它不工作:配置对象转到的网址,而不是在HTTP标头。

it's not working : the config object goes to the url and not in the http headers.

有没有办法做到这一点?

Is there a way to do that ?

标题 $资源是因为现有AngularJS 1.1.1。请确保您使用正确的版本。

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

格式

$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' }
    }
});