4

I've got a setup using a service to handle $resource that is as follows:

Service

factory('EventSlot', ['$resource', function ($resource){
    return $resource('/api/events/:id/slots/:slotId', {id: "@Id", slotId: "@slotId"},
    {
        signup: {
           method: 'PUT'
        }
     });
 }]);

Calling Function

EventSlot.signup({id: $scope.id, slotId: $scope.signUpSlot.id}, $scope.signUpSlot);

However, when the PUT call actually goes through it goes through to the endpoint: /api/events/123/slots/ where 123 is the appropriate @Id however @slotId never gets attached. So, what I want is /api/events/123/slots/456 but that never happens.

1 Answer 1

4

I think the logic works as expected and the possible reason why it was not working is because $scope.signUpSlot.id may be undefined.

I created a demo and you can open the browser console and see the call is actually made to the correct url:

PUT http://fiddle.jshell.net/api/events/123/slots/456 404 (NOT FOUND) 

Demo on jsFiddle

Sign up to request clarification or add additional context in comments.

1 Comment

That did seem to be the problem. I wasn't making sure it was declared beforehand. Thanks!

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.