betomoretti
betomoretti

Reputation: 2196

$resource update sends params in url angularjs

This is my resource:

socialnetworkServices.factory('UpdateResource', 
    [
        '$resource', 
        '$q', 
        function($resource, $q){
            return {
                update: function (url, sendParams) {
                    return $resource(
                                url, 
                                null, 
                                { 
                                    'update': {
                                        method:'PUT', 
                                        headers: {
                                            'Content-Type': 'application/json'
                                        }, 
                                        params: 
                                        sendParams 
                                     }
                                }).update();
                }
    }
}]);

My problem is when call this method update the object (sendParams) send in url and not in the body of request.

PD: I don't know how put pretty the code, sorry

Upvotes: 1

Views: 64

Answers (1)

Torsten Scholz
Torsten Scholz

Reputation: 866

You are using the params in your $resouce wrong. The payload you want to send has to be the argument of the actual update call you are doing:

socialnetworkServices.factory('UpdateResource', [
    '$resource',
    '$q',
    function($resource, $q) {
        return {
            update: function(url, sendParams) {
                return $resource(
                    url,
                    null, {
                        'update': {
                            method: 'PUT',
                            headers: {
                                'Content-Type': 'application/json'
                            }
                        }
                    }).update(sendParams); // Put your payload parameters here
            }
        }
    }
]);

Upvotes: 2

Related Questions