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:

enter image description here

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

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -