0

I have a resource, with which I want to build I dynamic url. The url will contain query string parameters like so

/path?ids=1&ids=2&ids=23

Here is what I have tried. I call this by passing an array of strings to this resource such as

['1', '2', '23']

The problem is that the value passed to the addParameters method is not the array but the string ':ids'.

Is this even possible?

By the way, I know about the obvious error in the line "queryString += '&ids=' + id;"

define([], function () {
    'use strict';

    var addParameters = function (ids) {
        var queryString = '';
            _.each(ids, function (id) {
                queryString += '&ids=' + id;
            });
        return queryString;
    }

    var resource = function ($resource) {
        return $resource(
            '/path?' +addParameters(':ids'), {},
            {
                query:
                {
                    method: 'GET',
                    isArray: true
                }
            }
        );  
    };
    resource.$inject = ['$resource'];
    return resource;
});
3
  • That would also generate an invalid URL /path?&ids=x... Commented May 13, 2016 at 14:14
  • I know about this - that's not the issue - I can deal with that issue, I just want to know that this sort of thing is possible and how. Commented May 13, 2016 at 14:16
  • github.com/angular/angular.js/pull/1921 - may help Commented May 13, 2016 at 14:35

1 Answer 1

1

Let's say your resource name is Test.

Test.query({ids: [1, 2, 3]}).$promise.then(function(res... etc
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.