AngularJS $资源GET中的多个参数 [英] Multiple parameters in AngularJS $resource GET

查看:139
本文介绍了AngularJS $资源GET中的多个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

'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

这是使用findRange REST服务的正确方法。这个将rmaID从1返回到4,但是如何从控制器中使用它以及服务中的正确语法是什么?

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?

在控制器中我想使用它类似的东西:

In controller I would like to use it something like that:

$scope.rmas = rmaService.findRange({id:'0'/'3'});

但这不起作用。

推荐答案

您可以覆盖网址,阅读 $ resource docs

You can override url, Read $resource docs


url - {string} - 特定于操作的url覆盖。支持网址模板,就像资源级网址一样。

url – {string} – action specific url override. The url templating is supported just like for the resource-level urls.

资源声明

findRange:{ 
    url: '/RMAServerMav/webresources/com.pako.entity.rma/:id/:to', 
    method: 'GET', 
    params:{ 
        id:'@id', 
        to: '@to'
    }
}

在控制器

$scope.rmas = rmaService.findRange({id:0, to: 3});

这篇关于AngularJS $资源GET中的多个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆