Transformrequest not working if not set globally

Hi Ionites,

I am having difficulty in using transfomRequest/default headers in my http request but if I set it in config globally it works well. What am I doing wrong? Please help me. Thanks

Code setting in config for global use:


// send all requests payload as query string
    $httpProvider.defaults.transformRequest = function(data){
        if (data === undefined) {
            return data;
        }
        return serialize(data);
    };

    // set all post requests content type
    $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';

Code Use per http request:

transformRequest: function (data, headersGetter) {
   if (data === undefined) {
        return data;
   }
     return serialize(data);
 },
  headers: function(data, headersGetter) {
       var headers = headersGetter();
       headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
       return headers;
 }