Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

limitToFilter() handles Infinity incorrectly #6771

Closed
flashbackzoo opened this issue Mar 20, 2014 · 7 comments
Closed

limitToFilter() handles Infinity incorrectly #6771

flashbackzoo opened this issue Mar 20, 2014 · 7 comments

Comments

@flashbackzoo
Copy link

If the limit argument is Infinity, it's parsed to NaN by int()

limit should remain Infinity

@flashbackzoo flashbackzoo changed the title limitToFilter handles Infinity incorrectly limitToFilter() handles Infinity incorrectly Mar 20, 2014
@caitp
Copy link
Contributor

caitp commented Mar 20, 2014

maybe this is a bug, but it seems like a weird thing to use Infinity for, what is the use case? Are you sort of trying to use this to toggle between limiting and not limiting?

caitp added a commit to caitp/angular.js that referenced this issue Mar 20, 2014
parseInt(Infinity, 10) will result in NaN, which becomes undesirable when the expected behaviour is
to return the entire input.

I believe this is possibly useful as a way to toggle input limiting based on certain factors.

Closes angular#6771
@flashbackzoo
Copy link
Author

Yeah pretty much. If a user sets itemsPerPage to 0, show all items. So something like:

<li ng-repeat="item in items | limitTo:itemsPerPage"></li>

@caitp
Copy link
Contributor

caitp commented Mar 20, 2014

I think the expected behaviour of limitTo:0 is probably the empty collection/string o_o, unless you're translating it manually

@flashbackzoo
Copy link
Author

I'm doing $scope.itemsPerPage = userSetVar === 0 ? Infinity : userSetVar; in my controller. So in my ngRepeat itemsPerPage will be an integer > 0 or Infinity. I get the expected behavior (all items in the collection showing) when I set a breakpoint in limitToFilter and set limit back to Infinity manually.

@caitp
Copy link
Contributor

caitp commented Mar 20, 2014

Alright, well, want to test my PR and see if that logic works for you? I'm not sure when/if it will land, though. It's a pretty simple fix and shouldn't be a breaking change, so we can probably triage it for the next beta, if not this one.

@flashbackzoo
Copy link
Author

Cool, I'll take a look later today. Thanks for the quick response :)

caitp added a commit to caitp/angular.js that referenced this issue Mar 21, 2014
parseInt(Infinity, 10) will result in NaN, which becomes undesirable when the expected behaviour is
to return the entire input.

I believe this is possibly useful as a way to toggle input limiting based on certain factors.

Closes angular#6771
caitp added a commit that referenced this issue Apr 15, 2014
parseInt(Infinity, 10) will result in NaN, which becomes undesirable when the expected behaviour is
to return the entire input.

I believe this is possibly useful as a way to toggle input limiting based on certain factors.

Closes #6771
Closes #7118
@caitp caitp closed this as completed in 5dee9e4 Apr 15, 2014
@jlsanchezsanz
Copy link

I think a better solution for this issue would be using array's length instead of Infinity.

Example: I wanted to show a paginated table with a search input and when input value is different from '', pagination should be disabled so that it can show all filtered items in the same view.

<input type="text" ng-model="searchLink" placeholder="Search">
...
<tr ng-repeat="link in links | orderBy:order:reverse | startFrom: (!searchLink || '') && ((currentPage - 1) * pageSize + 1) | limitTo: (!searchLink && pageSize) || links.length | filter:searchLink">

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

Successfully merging a pull request may close this issue.

3 participants