0

I'm using Angular with ngResource and i've got an api url:

GET http://my.com/rest/items?inState=TRANSIENT&inState=FINAL

How could I do query with two (not uniq) params 'inState'?

This is my Resource factory:

.factory('Resource', function ($resource, REST_URL) {
    return {
        items: $resource(REST_URL + 'rest/items',
            {},
            {
                get: {method: "GET", params: {inState: '@inState'}}
            })
    };
})

And this is the way I'm call it:

//GET http://my.com/rest/items?inState=TRANSIENT
Resource.items.get({inState: 'TRANSIENT'}, function (data) {
    //...
}, function (responce) {
    //...
});

This is works but the problem is in how I'm send params - as object: {inState: 'TRANSIENT'} I cannot write something like

{inState: 'TRANSIENT', inState: 'FINAL'}

beacuse of fields must be uniq

P.S. I know that it may be done with $http.

S Panfilov
  • 16,641
  • 17
  • 74
  • 96

2 Answers2

1

That's how to do this:

{inState: ['TRANSIENT', 'FINAL']

Example:

//GET http://my.com/rest/items?inState=TRANSIENT&inState=FINAL
Resource.items.getHistory({inState: ['TRANSIENT', 'FINAL']}, function (data) {
    //...
}, function (responce) {
    //...
});
S Panfilov
  • 16,641
  • 17
  • 74
  • 96
0

Not sure if you have control over what is consuming the parameters, but if you do you could try passing the parameters as an object with an array of objects in it, like this:

{ states : [{inState : 'TRANSIENT'}, {inState : 'FINAL'}]}

Then just iterate through the states array and check each inState property.

pje
  • 2,458
  • 1
  • 25
  • 26