Reputation: 12403
I've recently upgraded to AngularJS 1.2.0, and there a problem with passing array that breaks the site. In an example $http request I am passing fields like so:
$http.get({
url : 'users',
data : {
fields : 'user_id, user_name',
conditions : {
customer_id : current_site_id
},
join : ['customer_users']
}
});
In the last stable release of 1.0.8, the [] for the join was preserved, so in the php side it showed up as array and was iterable. In 1.2.0, the array is removed and the parameters pass as such by the browser to the server:
conditions:{"customer_id":"9a83a3db-673e-407f-9a0d-1f804c4dcd01"}
fields:user_id, user_name
join:customer_users //<---- THIS SHOULD BE AN ARRAY!
Because its not an iterable object, it breaks the php side. So aside from renaming all array variables from ['xyz']
to {'0': 'xyz'}
, to mimic the array behavior though not optimal, how can I ensure angularJS passes the value as an array?
Upvotes: 2
Views: 122
Reputation: 4471
I think your example should not work at all. It should be this:
$http({
method: 'GET',
url : 'users',
params : {
fields : 'user_id, user_name',
conditions : {
customer_id : current_site_id
},
join : ['customer_users']
}
});
And angular does the right job parsing the url since 1.1.1. The spec says if you have an array it'll be parsed like this ?join=item1&join=item2
. If the array only have one item it'll be ?join=item1
.
On the other hand jQuery.param()
will parse it like this: ?join[]=item1&join[]=item2
And it - if I'm right - will ensure that $_GET['join']
always be an array.
All in all, try 'join[]' : ['customer_users']
. It might work.
Upvotes: 1