Restangular getList with two parameters setting headers instead of request parameters

Based on my understanding of the restoration documents, a call Resource.getList('subElement',{query:param})should make a call/resource/subelement?query=param

I use Ransack on top of the rails APIs, and I'm trying to pass in some search parameters that take the form "q [field_eq] = foo".

Here is the controller:

.controller('PlaypenCtrl', function PlaypenCtrl(
  $scope,
  Resource
) {
  'use strict';

  var qParams;

  $scope.doIt = function() {
    qParams = {
      per_page: 10
    };
    qParams['q[some_field_eq]'] = 'foo';
    console.log(qParams); //Object {per_page: 10, q[some_field_eq]: "foo"}

    Resource.getList('subElement',qParams).then(function(list){
      console.log(list);
    });

  };
});

When I call doIt, this is logged:

Error: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': 'q[some_field_eq]' is not a valid HTTP header field name.

This makes sense because obviously this is not a valid HTTP header field name.

The question is, why did Restangular try to put the qParams object in the request headers? These should be query parameters, according to the documents.

If I select "subElement", everything will work as expected:

  $scope.doThat = function() {
    qParams = {
      per_page: 10
    };
    qParams['q[some_field_eq]'] = 'foo';
    console.log(qParams); //Object {per_page: 10, q[some_field_eq]: "foo"}

    Resource.getList(qParams).then(function(list){ 
      //calls /resource?per_page=10&q%5Bsome_field_eq%5D=foo
      console.log(list); //...a normal restangular list object, as expected
    });
  };

What am I missing?

+4
1

getList . subElement, :

Resource.all('subElement').getList(qParams)

, , .

+2

All Articles