Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

ngResource data object is undefined in transformRequest funcion #13674

@daverdalas

Description

@daverdalas

Hey, I'm using angular in version v1.4.8. I'm trying to do a very simple thing described in many places, however I can't make it work. Maybe this is a bug. Simple I want to change the data before sending it with ngResource. Here is my code:

Controller:

var vm = this;
vm.application = new Application();
vm.application.title = 'Test title';
Application.save({}, vm.application, function(){

 });

Service:

function application(ApiBaseUrl, $resource) {
    var actions = {
        'save': {
            metod: 'POST',
            url: ApiBaseUrl + "/applications",
            headers: { 'Content-Type': false },
            transformRequest: function (data) {
                console.log(data); //Returns 'undefined'
                return data;
            }
        }
    };
    return $resource(ApiBaseUrl + "applications/:id", {}, actions);
}

In the function transformRequest data object is always marked as 'undefined'. If I add data parametr to service ex. data: {test: 1} then the object appears in transformRequest. However, in this way, I can't pass it from the controller. Maybe I'm doing something wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions