Sergii Sergii - 9 months ago 66
AngularJS Question

REST AngularJS @resource parametrized request

I have next WEB API:

GET List<EventHistory> '/service/eventhistories'
GET EventHistory '/service/eventhistories/{id}'
DELETE EventHistory '/service/eventhistories/{id}'
PUT EventHistory '/service/eventhistories'
POST EventHistory '/service/eventhistories'

Using angular i want use @resource to get information from server.

angularApp.factory('eventHistoryFactory', function ($resource) {
return $resource('/inner/service/eventhistories/:id',{id:'@id'});

But using this declaration i do not have any API to request the page based on some data.

var pageRequest = {
size: size,
page: page

or to send update for eventHistory entity.


the first answer seems good, but i think this way more understandable and simply for begginers:

    eventHistoryFactory.get(pageRequest, function (returnData) {
      console.trace('request processed successfully: ' + returnData);;
    }, function (error) {
      console.log('request processed with error: ' + error);

to make page request in dynamic way the object should be build before request from ngTable current properties (use ngTable API).

Please pay your attention to eventHistoryFactory. It does not have parameter for pageRequest object, but it works -angular magic. By GET request in url you can see: