Maxime Lorant
Maxime Lorant

Reputation: 36181

Query parameters not taken into account in Restangular

I am using Restangular on my front-end and I want to query this URL:

http://localhost:4000/study?projectId=123456

It returns a list of studies associated to a certain project. So I have the following controller code for the moment:

MyApp.controller('ProjectDetailCtrl', function ($scope, $routeParams, Restangular) {
    // [...]
    var resource = Restangular.all('study');
    console.log($routeParams.projectId); // displays "123456", the current projectId
    resource.getList('study', {projectId: $routeParams.projectId}).then(function(studies){
        // Doing stuff 
    });
});

But it does not return the data I want. Indeed, when I look in the Network panel of Firefox, it queries http://localhost:4000/study, as if the parameter was not specified...
It seems to be the same code that the author give on Github, and every question on the web seems to use the same syntax. Why is my parameter ignored?

Upvotes: 1

Views: 228

Answers (1)

David Spence
David Spence

Reputation: 8079

The first parameter of the getList should be your query params. You've already specified the study bit of your url. You had an extra "study".

var resource = Restangular.all('study');
resource.getList({ projectId: $routeParams.projectId }).then(function(studies) {
    // do stuff
});

Upvotes: 1

Related Questions