lucassp lucassp - 2 years ago 137
Javascript Question

Setting application wide HTTP headers in AngularJS

Is there a way to set the

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 Source
$http.defaults.headers.common['Auth-Token'] = 'token';

It seems headers() normalizes the key names.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download