Semah Mhamdi Semah Mhamdi - 4 months ago 12x
AngularJS Question

What is the role of the AngularJS transformRequest function?

Can anyone tell me what is the role of this function in angularjs? I tried it in the http post method to webservice.

here is my code .

transformRequest: function(obj) {
var str = [];
for(var p in obj)
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
return str.join("&");

Without this function the code will not be executed because the form will be posted with a null variable.


This function adds all the parameters in the object passed with their value as a string which you can use in a GET.

For example:

   foo: bar
   bla: blabla

will be transformed to foo=bar&bla=blabla