Luke
Luke

Reputation: 598

Can you build a URL in Restangular with multiple variables?

I am trying to build a resource in Restangular with a URL that has multiple variables. The server variable is set, so I need to figure out how to do this client side.

This is the URL that I was using in ngResource:

'/api/v1/reports/shipped-orders/:reportDate/:orderType'

There isn't really any nesting past shipped-orders, it's just passing parameters through the URL.

I tried chaining them like:

_reports.one('shipped-order', '2013-11-04').one('', 'bulk')

But that turned out a url with double slashes in it.

Upvotes: 2

Views: 1336

Answers (2)

Oleg Belousov
Oleg Belousov

Reputation: 10111

It is also possible to do the following:

Restangular.all(varA).all(varB).all(varC);

Upvotes: 1

C1pher
C1pher

Reputation: 1972

I recently ran into this problem. Here's what I did:

myApp.factory('myRestService', ['Restangular', function(Restangular) {
    return {
        myFunction: function(varA, varB, varC) {
            var path = "rest/primaryPath/" + varA + "/" + varB + "/" + varC;
            var restObject = Restangular.all(path);
            var thePromise = restObject.getList();

            return thePromise;
        }
    };
}]);

By building the path myself, I was successfully able to use more than one variable and get a result from the Java Rest Service I was using in my project.

Upvotes: 3

Related Questions