I want to submit a header in every request, something like a: bbb.
// 无论是获取列表
$scope.books = myRes.query();
// 还是单独的一个项目
$scope.oneBook = myRes.get({id:2});
Can add a header to all RESTful requests, the content of the header is
ca-g-oo: data-dnwaec2ioagwqevnm
I tried various methods but couldn’t achieve it
$resource(url, [paramDefaults], [actions]);
url is the address to set the request
paramDefaults is the preset data to be submitted
action is a custom function method
It feels like it can be set through action, but it doesn’t work
// 如果把action设置成这样
$resource(
'ca/book/:id',
{},
{
query: {
header: {
"ca-g-oo": "data-dnwaec2ioagwqevnm"
}
},
get: {
header: {
"ca-g-oo": "data-dnwaec2ioagwqevnm"
}
}
}
);
I reported an error
Error: [$resource:badcfg] http://errors.angularjs.org/1.2.29/$resource/badcfg?p0=object&p1=array
interreputor can satisfy you
The problem is also solved. . When setting $resource, set the isArray attribute
isArray property
The complete code is as follows
Use route interceptor to define global header