Max Koretskyi
Max Koretskyi

Reputation: 105489

angular pass array in get request

I want to pass a query like that to the server:

/rest/articles/getTexts?tagIds[]=1&tagIds[]=88

I can do it with $.param like this:

var tagIds = [1, 88]
var param = $.param({tagIds: tagIds});

I've tried the same with angular:

var tagIds = [1, 88]
$http.get(serverUrl + "articles/getTexts" + {params:{tagIds: tagIds }})

But it produced the string like this:

/rest/articles/getTexts?tagIds=1&tagIds=88

Note the square brackets missing which leads to ovveriding of tagIds parameter on server side instead of making an array of it like in the case with jquery's param. Am I using angular's params in the wrong way or it's not possible to achieve what I want?

Upvotes: 1

Views: 3959

Answers (1)

JB Nizet
JB Nizet

Reputation: 691715

Not tested, but if you want the param name to be tagIds[], then that's also what the key of the params object should be:

params:{'tagIds[]': tagIds }

Upvotes: 3

Related Questions