AngularJS $resource query parameter with no value

142 Views Asked by At

From the AngularJS 1.6.x $resource documentation I know that I can pass in query name/value parameters using a JavaScript object. For example {foo: "bar"} for the path path/example will access a RESTful URL using something like path/example?foo=bar.

But what if I want to pass a query parameter with no value, e.g. path/example?foo? Do I use {foo: ""} or {foo: null} or some other form? Thanks in advance.

1

There are 1 best solutions below

0
Phil Ninan On

you should just be able to omit the query parameter. This is an example of a query that could return all users:

let User = $resource('/user/:userId', {userId: '@id'});
User.query().$promise.then(function(users) {
  allUsers = users;
});

https://docs.angularjs.org/api/ngResource/service/$resource#basic-usage