lucassp lucassp - 6 months ago 32
Javascript Question

Setting application wide HTTP headers in AngularJS

Is there a way to set the

$httpProvider
headers outside of
angular.module('myApp', []).config()
?

I'm getting an Auth-Token from the server after I login the user, and I need to add it as a HTTP Header to all following requests.

Answer
$http.defaults.headers.common['Auth-Token'] = 'token';

It seems headers() normalizes the key names.