Search code examples
javascriptruby-on-railsangularjsransack

How to pass nested parameters using angular


I am trying to send a get request to my rails backend using angular. So what am looking for is the request like this

Parameters: {"location"=>"london", "q"=>{"price_gteq":"33333", "price_lteq":"7777"}}

So in my app.js I tried below code to send the request with the parameters. I am now getting unexpected / and the second nested parameter is not showing aswell as seen below.

  $http({
        url: "/search.json",
        method: "GET",
        params: {location: $scope.searchLocation, q: {price_gteq: $scope.min_price, price_lteq: $scope.max_price} }
    })

This is what i get when I try like above

Parameters: {"location"=>"london", "q"=>"{\"price_gteq\":\"33333\"}"}

Could someone tell me what am doing wrong here??


Solution

  • By default angular uses $httpParamSerializer which actually can handle nested parameters. Check if your $http uses this service. If for some reason it doesn't work, you can write own paramSerializer and pass it into $http configuration object.

    Also check if price_lteq present at the moment, when you send request.