1
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;
}]);
查詢:
$scope.userTickets = Ticket.listByOwner({
id : $rootScope.user.id
}, function(){
//success
}, function(response){});
結果:
Angularjs構建了一個錯誤的URL,/api/tickets
但它應該是/api/tickets/2/owner
。任何想法爲什麼?
您確定$ rootScope.user.id不是undefine d? –
@MarekTakac nope它被設置 –