I would like to know how to pass headers to AngularJS $resource method

Here is the factory method

.factory('DataRepository', function ($resource) {

return $resource(serviceUrlPrefix + '/api/v1/AppList/:id', { id: '@id' }, { 'query': { method: 'GET', isArray: false }, 'update': { method: 'PUT', AppList: '@req', headers: { 'X-Requested-With': 'XmlHttpRequest' } } });

});

Here is the call to the dataRepository

dataRepository.update({ id: req[uniqueIDColumn] }, req, function (data) {

},

function (error) {

});

This code works fine. But i have few queries

Question 1:

Rather than specifying the headers in the factory method , how can i specify it in the call to the factory method? I tried few methods but it didnt work out.

Question 2:

I specified the header in the update method in the factory. When i perform "Save" using that factory, that header has been taken by default. But i have specified it explicitly for PUT method. Right? Why and how?

Question 3:

If i would like to specify the header for the particular factory in common for all Http methods, what is the way to do it?

Question 4:

What is the nomenclature for passing the parameters and the significance of "@" symbol before parameter and also in the below part, AppList is the parameter name used in the WebAPI, is it mandatory that it should match the parameter name in the WebAPI method, if its not matching, its not working:(

AppList: '@req'

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐