Again: Add Authorization header to AngularJS $http

In my last post I showed how I add an Authorization header to outgoing $http calls in AngularJS. I’ve changed the way I do it, this which I think is easier to read.

  .factory('RequestInterceptor', [
    (AuthDataService) ->
      interceptor = 
        request: (config) ->
          header = AuthDataService.getAuthData()
          if header then config.headers['Authorization'] = "Basic #{header}"

angular.module('app').config(['$httpProvider', ($httpProvider) ->
  $httpProvider.interceptors.push 'RequestInterceptor'

The AuthDataService is the same as in my last post, but without the the setting of $http.defaults.headers.common['Authorization'].