I add a couple of actions to the AngularJS resource, but when I call the action, my transformRequest function does not receive the call:
var _resource = $resource('api/NewItem/:id', { id: '@id' }, { create: { method: 'POST', transformRequest: function (data, headersGetter) { var result = JSON.stringify(data.productIntro); return result; } }, update: { method: 'PUT', transformRequest: function (data, headersGetter) { var result = JSON.stringify(data.productIntro); return result; } } });
If I add the function globally to the application, it will work:
var newItemApp = angular.module('newItemApp', ['ngResource']) .config(function ($httpProvider) { $httpProvider.defaults.transformRequest = function(data) { if (data === undefined) { return data; } var result = JSON.stringify(data.productIntro); return result; }; });
What I need to do is remove the root element from any POST or PUT action, because the default binding of the model in Web Api does not bind the json object when this object has a named root.
source share