[英]Angularjs: Pass parameter from controller to factory
我有以下代碼在服務中
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}
});
}]);
});
從控制器我調用這個工廠方法如何從控制器傳遞參數到這個testService?
以下是控制器中用於調用此工廠的代碼
user_resources.testService().$promise.then(function(data) {
console.log("****************************");
console.log(data);
$scope.mylist=data;
});
這不是$resource
如何運作。
$resource("http://11.11.11.11/url/index.php",
{'testService':{method:"GET",url:'http://11.11.11.11/url/index.php',isArray:true}})
然后你用它來調用它:
var theObjToSend = {
method:method_name,
params:
{
param1:value,
param2:value
}
};
new user_resources({data: theObjToSend}).testService();
要么
user_resources.testService({data: theObjToSend});
它將序列化對象,因此它可能看起來很奇怪。 您不使用查詢參數的任何原因?
例如
?method=method_name¶ms={param1:value,param2:value}
你應該檢查這個視頻: https : //egghead.io/lessons/angularjs-using-resource-for-data-models
return $resource("http://11.11.11.11/url/index.php");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.