javascript - How to pass query parameter array using Angular $resource -


i'm trying enable feature users can searched based on multiple tags (an array of tags) using following structure:

get '/tags/users?tag[]=test&tag[]=sample' 

i have working on node server , have tested using postman. issue i'm running how structure get request in angular service using $resource. have found documentation $http stating adding params:{'tag[]': tag} request object trick, cannot find regarding $resource.

in angular can pass array query string using $resource

in controller:

    angular.module('myapp').controller('usercontroller',['$scope','userservice', '$location',         function($scope, userservice, $location){             $scope.searchquery = {};              $scope.searchusers = function() {                 $scope.roles = ['admin', 'register', 'authenticate'];                 $scope.searchquery.name ='xxx';                 $scope.searchquery['roles[]'] = $scope.roles;                 userservice.searchusers($scope.searchquery)                     .$promise.then(function (response) {                         $scope.users = response.users;                     });             };        }    ]); 

in service:

    angular.module('myapp').factory('userservice', ['$resource',   function($resource) {      return {         searchusers: function(searchquery){             var searchrequest = $resource('/auth/search/user', {}, {                 'get': {method: 'get'}             });             return searchrequest.get(searchquery);         }     };   } ]); 

the request url like:

/auth/search/users?name=xxx&roles%5b%5d=admin&roles%5b%5d=register&roles%5b%5d=authenticate 

you %5b%5d instead of [] in request url

and if expect return array instead of object should use

'get': {method: 'get', isarray: true} 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -