duplicate query string parameters with $resource or $http

2,996 views
Skip to first unread message

pelado

unread,
Nov 20, 2012, 6:11:36 PM11/20/12
to ang...@googlegroups.com
The echonest API provides some methods which can be queried multiple times using a 'bucket' parameter.  I can't get $resource nor $http to send multiple parameters that have the same name (bucket). Angular strips out the repeated parameters before sending the request.  
Using $resource I want to include something like this:
Can someone help me?

Thanks

Pawel Kozlowski

unread,
Nov 20, 2012, 6:45:25 PM11/20/12
to ang...@googlegroups.com
Hi

If I'm not mistaken this PR should solve your problem:

Cheers,
Pawel
--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.
 
 


--
Question? Send a fiddle (http://jsfiddle.net/pkozlowski_opensource/Q2NpJ/) or a plunk (http://plnkr.co/)
Need help with jsFiddle? Check this: http://pkozlowskios.wordpress.com/2012/08/12/using-jsfiddle-with-angularjs/

Looking for UI widget library for AngularJS? Here you go: http://angular-ui.github.com/

pelado

unread,
Nov 21, 2012, 7:28:00 AM11/21/12
to ang...@googlegroups.com
Thanks Pawel. That was just what I needed for $http, although it seems $resource still doesn't allow arrays to be duplicated.


John Meiss

unread,
Apr 11, 2013, 4:11:03 AM4/11/13
to ang...@googlegroups.com
Hi Pelado,

Have you found a solution to that problem? I'm experiencing the same issue.

Thx.
Message has been deleted

Nils Gehlenborg

unread,
Feb 10, 2014, 1:12:12 PM2/10/14
to ang...@googlegroups.com
Pass the values for the query parameter as an array, e.g. order_by: [ "-is_current", "name" ]. This will result in a query string like this: ...&order_by=-is_current&order_by=name&...

Nils

Chris Jones

unread,
Aug 25, 2014, 11:28:22 PM8/25/14
to ang...@googlegroups.com
I was able to create the following get request: (notice there are 2 deliverytypeid's)

http://localhost:8080/rule?deliverytypeid=1&deliverytypeid=3&inputtypeid=1&languageid=1&materialtypeid=1


Here is my $promise that I use to call the $resource:

            var selectedInputTypeId = $scope.selectedInputType.id;
            var selectedMaterialTypeId = $scope.selectedMaterialType.id;
            var selectedLanguage = $scope.selectedLanguage.id;
            var selectedDeliveryTypes = getSelectedDeliveryTypeIds();  //This returns an array of numbers.

            var rulesPromise = MyService.getRules(selectedInputTypeId, selectedMaterialTypeId, selectedLanguage, selectedDeliveryTypes);
            rulesPromise.$promise.then(function (rulesData) {
                $scope.rules = rulesData
            });


The key for me was to not specify defaultParams in the $resource call -->  var ruleResource = $resource('/rule', {}, {
Here is my factory method:

myServices.factory('MyService', [ '$resource', function ($resource) {
    var ruleResource = $resource('/rule', {}, {
        'get': {method: 'GET', isArray: true}
    });

    return {
        getRules: function(inputTypeId, materialTypeId, languageId, deliveryTypeId) {
            var ruleResponse = ruleResource.get({inputtypeid:inputTypeId, materialtypeid:materialTypeId, languageid:languageId, deliverytypeid:deliveryTypeId });
            return ruleResponse;
        }
    };

} ]);
Reply all
Reply to author
Forward
0 new messages