1

How can I use the filtered array in orderByName in the newFirst filter? Is this possible?

filter = (list | orderByName | newFirst )

I have a list sorted alphabetically and I need to sort again by if it's new or not.

1 Answer 1

1

Yes, you can do that. But you have to take care that the second ordering function doesn't override the result of the first one. The easiest way to achieve that, is with the standard orderBy filter of AngularJS with multiple sorting parameters:

Using object properties:

ng-repeat="item in list | orderBy:['name', 'isNew']" 

Using custom comparators:

ng-repeat="item in list | orderBy:[orderByName, newFirst]"

For the second way you need to implement the functions orderByName and newFirst as comparator function (see https://docs.angularjs.org/api/ng/filter/orderBy).

Sign up to request clarification or add additional context in comments.

1 Comment

Daniel , Thank you very much, for your help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.