Domanda

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.

È stato utile?

Soluzione

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top