Angularjs resource builds wrong resource url -
resource:
angular.module('ticketservice', ['ngresource']) .factory('ticket', ['$resource', function($resource){ var ticket = $resource('/api/tickets/:id1/:action/:id2', { id1:'@id' }, { list: { method: 'get' }, listbyowner: { method: 'get', params: { action:'owner', id1:"@id" } } update: { method: 'put', params:{} } }); return ticket; }]);
query:
$scope.usertickets = ticket.listbyowner({ id : $rootscope.user.id }, function(){ //success }, function(response){});
result:
angularjs builds wrong url, /api/tickets
should /api/tickets/2/owner
. ideas why?
the @
indicates angular should attribute on data object, second parameter (optional) in ticket service methods. in first parameter specify request parameters. there 2 ways can fix this:
- add empty object first parameter
$scope.usertickets = ticket.listbyowner({},{ id : $rootscope.user.id }, function(){ //success }, function(response){});
- or rename request parameter object key (from
id
id1
):
$scope.usertickets = ticket.listbyowner({ id1 : $rootscope.user.id }, function(){ //success }, function(response){});
Comments
Post a Comment