How to set a default HTTP header in a service

18 views
Skip to first unread message

Johannes Zorn

unread,
Feb 4, 2014, 5:33:59 AM2/4/14
to ang...@googlegroups.com
Hi,

I implemented an httpInterceptor in the config block of an application that requires access to the $httpProvider to set the default Authorization header. Now I'd like to move this interceptor to a service. I assume it is not possible to access the $httpProvider in a service. Is there another way to set a header for all following HTTP requests? What's the best practise in that case?

Best,
Johannes Zorn

Matt Goodall

unread,
Feb 4, 2014, 5:48:08 AM2/4/14
to ang...@googlegroups.com
You can set future request defaults via the standard $http service's
$http.defaults. I'm adding an Authorization header using that and it
seems to work well. See
http://docs.angularjs.org/api/ng.$http#description_setting-http-headers
for details.

- Matt

Johannes Zorn

unread,
Feb 4, 2014, 5:55:35 AM2/4/14
to ang...@googlegroups.com
Hi Matt,

I must have missed this. Thank you!

Johannes



--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/Us6JbgP_cps/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages