I need to send an application ID from my angular app to my api with every request. This will most likely be sent as a parameter or in a header. How can I configure $http to send this with every request?
Asked
Active
Viewed 747 times
1 Answers
2
Set a property on $http.defaults.headers
:
$http.defaults.headers.common['My-Header'] = 'value';
Angular docs: Setting HTTP Headers

Marc Kline
- 9,399
- 1
- 33
- 36
-
This seems like the right solution but it's currently throwing this error 2 XMLHttpRequest cannot load http://localhost:8080/items. Request header field My-Header is not allowed by Access-Control-Allow-Headers. Do I additionally need to set it as an allowed header? and is there a way to set default params or body values? – Constellates May 23 '14 at 02:06
-
Yes, it seems you need to set a response header for your OPTIONS preflight request to indicate that your special header is allowed during the actual request: http://www.w3.org/TR/cors/#access-control-allow-headers-response-header – Marc Kline May 23 '14 at 02:10
-
To send default params or body values: http://stackoverflow.com/questions/23742561/provide-default-parameters-automatically-with-resource/23744333#23744333 – Marc Kline May 23 '14 at 02:11
-
1I'm still trouble shooting the Access-Control-Allow-Headers, but method of setting params will do the trick for this. Thank you! The blog post linked in that question gave me a much better understanding of http interceptors. – Constellates May 23 '14 at 03:07