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

Collections are zero-length inside $then #154

Closed
adammw opened this issue Sep 24, 2014 · 5 comments
Closed

Collections are zero-length inside $then #154

adammw opened this issue Sep 24, 2014 · 5 comments
Labels

Comments

@adammw
Copy link

adammw commented Sep 24, 2014

When accessing a collection from inside $then, the array length of the collection is zero regardless of the data.

$scope.users = User.$search({ page: $scope.page }).$then(function(users) {
  console.log(users.length);
  users.forEach(function(user) {
    console.log(user);
  });
});
@iobaixas
Copy link
Member

I'll take a look at it, can you tell if this a browser specific issue? if so against which browser are you running your code?

@iobaixas iobaixas added the bug label Sep 24, 2014
@markusklooth
Copy link

I'm experiencing the same bug. The $response and $status are correctly set within the $send method. Is the $unwrap method inside Collection.$fetch asynchronies?

@iobaixas
Copy link
Member

I do not seem to be able to reproduce the error, could you share some more information about the code that triggers it? any special unpack implementation? A gist would be even better...

@adammw
Copy link
Author

adammw commented Sep 25, 2014

@iobaixas here's a test case that reproduces the problem.
http://codepen.io/adammw/pen/JLnwj
I'm running it against Chrome 37.

@iobaixas
Copy link
Member

Thanks! that did it! I'm releasing a fix in a moment.

On a side note, about the exampled you posted: Be careful when using console log, if you pass it an object (or an array in this case), it keeps the output updated with the content of the object (is not a snapshot). Thats why console.log(array) and console.log(array.length) did not match and not because of the bug. If you instead where to use console.log(array[0]) and console.log(array.length) then the outputs would be consistent (should print undefined and 0).

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

No branches or pull requests

3 participants