0

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;     
});
2
  • what parameter you want to pass? Commented Apr 24, 2014 at 12:15
  • want to pass this portion params:{param1:value,param2:value} as parameter. Commented Apr 24, 2014 at 12:18

2 Answers 2

1

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&params={param1:value,param2:value}
Sign up to request clarification or add additional context in comments.

3 Comments

if i open 'testService':{method:"GET",url:'11.11.11.11/url/index.php?data={',isArray:true} and user_resources.testService({data: theObjToSend}).$promise.then(function(data){ console.log("####################"); console.log(data); }); then data is not available
I dont understand your comment @PriyaBhatt
i am using user_resources.testService({data: theObjToSend}).$promise.then(function(data){ console.log("####################"); console.log(data); }); to get data from url but it is not available
1

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");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.