Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse response with angularjs-rails-resource #95

Open
duleorlovic opened this issue May 19, 2016 · 1 comment
Open

Parse response with angularjs-rails-resource #95

duleorlovic opened this issue May 19, 2016 · 1 comment

Comments

@duleorlovic
Copy link

It is very easy (<10mins) to start with this nice tool. Thanks. 👍
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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant