Angular $ endpoint with two parameters

I have a setup using a service to process $ resource, which looks like this:

Service

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

Call function

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

However, when the PUT call actually passes, it goes to the endpoint: /api/events/123/slots/ , where 123 is a suitable @Id , however @slotId never joins. So I want /api/events/123/slots/456 , but that will never happen.

+4
source share
1 answer

I think the logic works as expected, and the possible reason it doesn't work is because $scope.signUpSlot.id may be undefined .

I created a demo version, and you can open the browser console and see that 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

+4
source

Source: https://habr.com/ru/post/1494187/


All Articles