2

Using AngularJS 1.2.16 and angular-resource 1.2.16.

I have a resource like:

$resource('api/:variable/path',
    {
        variable:'@variableName'
    });

When I do a get using something like

resourceIns.get({variable:'taco'});

The resulting ajax call replaces :variable properly and i get

api/taco/path

If I do a post like

resourceIns.save({variable:'taco'});

the resulting ajax call looks like

api/path

and 'taco' gets put in the POST body...

I've had trouble finding others complaining about this so, maybe this is what's supposed to happen?

edit: I just discovered that get uses 'variable' and save/POST uses 'variableName' in the above example. Anybody have an explanation for that?

Here's a fiddle showing the situation: fiddle

3
  • I don't think I've ever used a config where the parameter and field names were different. I'd also expect resourceIns.get({variableName:'taco'}); to work and not the other way around. Commented Jun 3, 2014 at 22:33
  • @HackedByChinese - It's looking like using the same field names would be a good practice. I mostly think it's weird that it appears to be completely swapped for the different cases. I would expect to be able to change a get to a save and have the only change be from a GET to a POST... Commented Jun 3, 2014 at 22:40
  • I agree. I'll look at the source, perhaps it's a bug in .get(). Commented Jun 3, 2014 at 22:45

1 Answer 1

3

I ran across the same issue or one that presented itself in the same fashion. My resource, too, was not respecting parameters passed in through a .post method.

I was able to get it to work by directly passing in the expected parameters.

Using a $resource:

angular.module('myApp')
  .factory('ModuleProductProducts', function ($resource) {
    return $resource('/module-api/product-products/:siteId/:id/:controller', {
      id: '@id'
    },
    {
        'updateMedia': {
            method: 'POST',
            url: 'module-api/product-products/:id/media/:mediaId',

            // *** Here ***
            params: {
                id: '@id',
                mediaId: '@mediaId'
            }
            // ************
        }
    });
  });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.