Multiple parameters in AngularJS $resource GET

Sami picture Sami · Jun 2, 2015 · Viewed 27.3k times · Source
'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?

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

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

but this is not working.

Answer

Satpal picture Satpal · Jun 2, 2015

You can override url, Read $resource docs

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

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