Sergey Panfilov Sergey Panfilov - 3 months ago 9
AngularJS Question

Is it possible to use repeating params in ngResours query

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.

Answer

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) {
    //...
});