Q:

Add a custom header to $http

I have a factory with a number of functions that look like this,
doFunction: function () {
   return $http({
       method: 'POST',
       url: 'https://localhost:8000/test',
       data: {},
       headers: {
          "My_Header": $rootScope.value,
          "Content-Type": "application/json; charset=utf-8"
       }
    })
}

I want to add a custom header called My_Header, but I dont think this is the correct way of doing it since it is not included on the request. What am I doing wrong here?

A:

Create a new HttpHeaders() from here.
Then add your header: .append('My_Header', $rootScope.value).
Now use these new headers for your request.

