-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat(sliceFilter): create slice filter - more powerful limitTo filter #6399
Conversation
This creates a new filter that passes a string or array to native slice() method. This is be useful for pagination or extracting a portion of a string or array. It differs from the limitTo filter because limitTo only has one bound, a starting position. Creating a new filter is more intuitive and reflective of native Javascript rather than extending limitTo. It should close issue angular#5355.
Thanks for the PR! Please check the items below to help us merge this faster. See the contributing docs for more information.
If you need to make changes to your pull request, you can update the commit with Thanks again for your help! |
Not sure this should be in Angular core, but thanks for the PR! It might be good to publish this as a module on bower/npm in the mean time. |
The ability to have a portion of an array/string is very helpful if you want to do pagination with filters instead of needing to write a controller method. The limitTo filter has only a starting index value, which could be refactored to have a second bound (as mentioned #5355). However there was a lot of doubt in my mind that it would be a clean and logical to do that. If its not for the core, no problem, but the issue I linked to has a tag requesting a PR for this so I went for it. If there is a more appropriate approach, I'd be happy to rewrite it. |
I don't know how I feel about having 2 filters in core that do more or less the same thing. IMO we should either:
Personally I would vote for the fist option. |
I have another branch the first option already, though its a little confusing when you can accept a negative limit and positive offset. I'd be happy to close this and open another with limitTo having a second argument for |
@pkozlowski-opensource "extend the limitTo filter to take 2 args" - this sounds like the right course of action, IMO. |
I just sent a PR (#6625) that extends limitTo functionality, so the second argument will indicate the starting index. Here is a plunker to test (based on doc example): http://plnkr.co/edit/eQF91pmy4Ji7ZckYfE12?p=preview |
02dc2aa
to
fd2d6c0
Compare
cad9560
to
f294244
Compare
e8dc429
to
e83fab9
Compare
4dd5a20
to
998c61c
Compare
with aaae3cc, this is no longer needed |
Request Type: feature
How to reproduce:
Component(s): misc core
Impact: small
Complexity: small
This issue is related to:
Detailed Description:
This creates a new filter that passes a string or array to native slice() method. This is be useful for pagination or extracting a portion of a string or array. It differs from the limitTo filter because limitTo only has one bound, a starting position. Creating a new filter is more intuitive and reflective of native Javascript rather than extending limitTo.
Other Comments:
It should close issue #5355.
Includes passing tests and docs.