angular-tasty-resource icon indicating copy to clipboard operation
angular-tasty-resource copied to clipboard

The .query() just returns an empty array

Open audoeyop opened this issue 10 years ago • 5 comments

The results [] array in queryURL that gets returned doesnt sync up w/ the values pushed onto it in the promise.then function

audoeyop avatar Oct 17 '14 19:10 audoeyop

@gsterjov, any feedback?

audoeyop avatar Nov 07 '14 18:11 audoeyop

Sorry, it has been a while. I'm not sure I know what you mean. Would you mind providing an example.

gsterjov avatar Nov 07 '14 23:11 gsterjov

I figured it out... When I tried:

$scope.users = User.query();
console.log($scope.users);

An empty array was printed to the console. I realized that (after looking through your code) an empty array was printed b/c the ajax query hadn't had a chance to fetch the request.

The following worked for me:

$scope.users = User.query(function(response){
  $scope.users = response.data.objects;
  console.log($scope.users)
});

audoeyop avatar Nov 08 '14 17:11 audoeyop

I love this module btw.. You've saved me a lot of time re-writing repetitive code. Can you mention this in documentation so that noobs like myself won't get confused about why the data isn't immediately available after .query(), .get(), etc. function calls?

audoeyop avatar Nov 08 '14 17:11 audoeyop

Found this answer after 3 hours of debugging (I don't know why I did't google it right away). Thanks!

alohaaloha avatar Feb 18 '16 04:02 alohaaloha