Reputation: 1481
I have following code in service
define(['./module'], function(services) {
'use strict';
services.factory('user_resources', ['$resource', '$location', function($resource, $location) {
return $resource("", {},
{
'testService':{method:"GET",url:'http://11.11.11.11/url/index.php?data={method:method_name,params:{param1:value,param2:value,}}',isArray:true}
});
}]);
});
from controller i am calling this factory method how to pass parameters to this testService from controller?
following is code in controller to call this factory
user_resources.testService().$promise.then(function(data) {
console.log("****************************");
console.log(data);
$scope.mylist=data;
});
Upvotes: 0
Views: 2966
Reputation: 58632
Thats not how $resource
works.
$resource("http://11.11.11.11/url/index.php",
{'testService':{method:"GET",url:'http://11.11.11.11/url/index.php',isArray:true}})
Then you call it with:
var theObjToSend = {
method:method_name,
params:
{
param1:value,
param2:value
}
};
new user_resources({data: theObjToSend}).testService();
or
user_resources.testService({data: theObjToSend});
Its going to serialize the object so it might look weird. Any reason why you dont use query parameters?
e.g.
?method=method_name¶ms={param1:value,param2:value}
Upvotes: 1
Reputation: 8646
You should really check this vid: https://egghead.io/lessons/angularjs-using-resource-for-data-models
return $resource("http://11.11.11.11/url/index.php");
Upvotes: 1