Semah Mhamdi Semah Mhamdi - 1 year ago 95
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.

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download