'use strict';
angular.module('rmaServices', ['ngResource'])
.factory('rmaService', ['$resource',
function ($resource) {
return $resource(
'/RMAServerMav/webresources/com.pako.entity.rma/:id',
{},
{
delete: { method: 'DELETE', params: {id: '@rmaId'}},
update: { method: 'PUT', params: {id: '@rmaId'}},
//RMAServerMav/webresources/com.pako.entity.rma/0/3
findRange:{method: 'GET', params:{id:'@rmaId'/'@rmaId'}}
});
}]);
RMAServerMav/webresources/com.pako.entity.rma/0/3
This is correct way to use findRange REST service. This one returns the rmaID from 1 to 4, but how can I use this from controller and what is the correct syntax in service?
这是使用findRange REST服务的正确方法。这个将rmaID从1返回到4,但是如何从控制器中使用它以及服务中的正确语法是什么?
In controller I would like to use it something like that:
在控制器中我想用它来做:
$scope.rmas = rmaService.findRange({id:'0'/'3'});
but this is not working.
但这不起作用。
2 个解决方案
#1
23
You can override url, Read $resource docs
您可以覆盖url,阅读$ resource docs
url – {string} – action specific url override. The url templating is supported just like for the resource-level urls.
url - {string} - 特定于操作的url覆盖。支持url模板,就像资源级url一样。
In resource declaration
在资源申报中
findRange:{
url: '/RMAServerMav/webresources/com.pako.entity.rma/:id/:to',
method: 'GET',
params:{
id:'@id',
to: '@to'
}
}
In Controller
在控制器中
$scope.rmas = rmaService.findRange({id:0, to: 3});
#2
-1
Try changing your service using it in the controller like this:
尝试在控制器中使用它更改您的服务,如下所示:
'use strict';
angular.module('rmaServices', ['ngResource'])
.factory('rmaService', ['$resource',
function ($resource) {
var service ={}
service.rma = function(){ // name it whatever you want
return $resource(
'/RMAServerMav/webresources/com.pako.entity.rma/:id',
{},
{
delete: { method: 'DELETE', params: {id: '@rmaId'}},
update: { method: 'PUT', params: {id: '@rmaId'}},
//RMAServerMav/webresources/com.pako.entity.rma/0/3
findRange:{method: 'GET', params:{id:'@rmaId'/'@rmaId'}}
});
};
return service;
}]);
//in controller
rmaService.rma()
.then(function(resource){
$scope.rmas = resource.$findRange({id:'0'/'3'});
});
I have no idea if this will work BTW, because I have no use ngResource but that is how I code my factory services.
我不知道这是否适用BTW,因为我没有使用ngResource,但这就是我对工厂服务进行编码的方式。
#1
23
You can override url, Read $resource docs
您可以覆盖url,阅读$ resource docs
url – {string} – action specific url override. The url templating is supported just like for the resource-level urls.
url - {string} - 特定于操作的url覆盖。支持url模板,就像资源级url一样。
In resource declaration
在资源申报中
findRange:{
url: '/RMAServerMav/webresources/com.pako.entity.rma/:id/:to',
method: 'GET',
params:{
id:'@id',
to: '@to'
}
}
In Controller
在控制器中
$scope.rmas = rmaService.findRange({id:0, to: 3});
#2
-1
Try changing your service using it in the controller like this:
尝试在控制器中使用它更改您的服务,如下所示:
'use strict';
angular.module('rmaServices', ['ngResource'])
.factory('rmaService', ['$resource',
function ($resource) {
var service ={}
service.rma = function(){ // name it whatever you want
return $resource(
'/RMAServerMav/webresources/com.pako.entity.rma/:id',
{},
{
delete: { method: 'DELETE', params: {id: '@rmaId'}},
update: { method: 'PUT', params: {id: '@rmaId'}},
//RMAServerMav/webresources/com.pako.entity.rma/0/3
findRange:{method: 'GET', params:{id:'@rmaId'/'@rmaId'}}
});
};
return service;
}]);
//in controller
rmaService.rma()
.then(function(resource){
$scope.rmas = resource.$findRange({id:'0'/'3'});
});
I have no idea if this will work BTW, because I have no use ngResource but that is how I code my factory services.
我不知道这是否适用BTW,因为我没有使用ngResource,但这就是我对工厂服务进行编码的方式。