angular-paginate-anything icon indicating copy to clipboard operation
angular-paginate-anything copied to clipboard

Parse response with angularjs-rails-resource

Open duleorlovic opened this issue 8 years ago • 1 comments

It is very easy (<10mins) to start with this nice tool. Thanks. :+1: But I have a problem since I use angular-rails-resource and I need to parse response, so for example I can call user.save()

Is there any callback that I can use to parse response ? I see that there is loadPage so I tried to map response with new User userObject. It works but I have a problem that it renders previous page (not the current) since in the time when this event callback is called, my vm.usersObject still have old values (from previous page).

// template in jade
bgf-pagination(collection="vm.usersObject" url="'http://localhost:3001/api/v1/users'")

// coffee script
    $scope.$on 'pagination:loadPage', (event, status, config) ->
      console.log config.headers.Range
      return unless vm.usersObject # on first load it is empty
      vm.users = vm.usersObject.map (userObject) -> new User userObject
      console.log vm.usersObject[0].id

I tried with $scope.$apply() but it says $digest already in progress, as expected.

duleorlovic avatar May 19 '16 09:05 duleorlovic

Just to note that I fixed with $timeout hack. If there is no better solution, please close the issue.

    $scope.$on 'pagination:loadPage', (event, status, config) ->
      $timeout ->
        vm.users = vm.usersObject.map (userObject) -> new User userObject

duleorlovic avatar May 19 '16 09:05 duleorlovic