angularjs - Is it possible to perform a Restangular GET with multiple query parameters? -
i've been attempting perform restangular multiple query parameters (for simple pagination) , doesn't seem possible--at least i'm trying do. here's i'm attempting do:
restangular.all('elevation').get({ pageparam: page, pagesizeparam: pagesize }).then(function(data) { console.log(data); });
with expected response looking like:
{ totalrecords: 233, elevations: {...} }
this not work , results in following:
get http://localhost:24287/elevation/[object%20object] 404 (not found)
i attempting utilizing customget
results in same problem above.
the way i'm able pass multiple query parameters using getlist
. unfortunately when utilizing getlist
unsurprisingly following error thrown:
error: response getlist should array , not object or else
to resolve issue, restangular documentation states in my response wrapped metadata. how data in case? section need use addresponseinterceptor
i've done so:
restangularprovider.addresponseinterceptor(function(data, operation, what, url, response, deferred) { var newresponse = []; if(response.data.totalrecords !== undefined) { newresponse.elevationdata= {}; newresponse.elevationdata.totalrecords = response.data.totalrecords; newresponse.elevationdata.elevations = response.data.elevations; } return newresponse; });
after jumping through hoops convoluted solution in fact work. there not easier way call restangular's get
multiple query parameters , object returned?
at point, magnitude easier take restangular out of question , use $http service so:
$http.get('http://localhost:24287/elevation?page=' + page + '&pagesize=' + pagesize).then(function(result) { console.log(result.data.totalrecords); console.log(result.data.elevations); });
though want figure out better way restangular.
any ideas appreciated! thanks!
that's deadly simple, querying ressource url without id, specific query params, , returning single object not restful.
error: response getlist should array , not object or else
it's precisely telling truth : query return array, because haven't specified unique identifier (everything else not unique).
at point, magnitude easier take restangular out of question , use $http service
definately, since restangular focuses on restful resource proxying, or you're gonna have tweak (interceptors, customget, ...)
Comments
Post a Comment