Tuesday, 13 August 2013

How do I pass parameter to an angular service?

How do I pass parameter to an angular service?

I have made simple HTTP based API and I would like to make POST calls to
it like:
http://mysite.com/api/v1/person/something
http://mysite.com/api/v1/person/else
http://mysite.com/api/v1/person/someword
in general
http://mysite.com/api/v1/person/<word>
In angular I have created a service
angular.module('personService', ['ngResource']).
factory('Person', function($resource){
return $resource('/api/v1/person/:word', {}, {
action: {method:'{POST', params:{ ???? }, isArray :
false},
});
});
And in my controller which uses the service I would like to be able to
call Person.action() and pass it a parameter to determine what word is,
for example:
Person.action('something', function(d) {
console.log('Result of api/v1/person/something')
});
but I'm not sure how to connect the two. See ???? in the third code block.

No comments:

Post a Comment