0

I'm getting two items back from my API, one has a startDate and one has an endDate and I was wondering if it's possible to order them by their parameter string?

Data:

[
  {
    name: "Item 1",
    type: "Start Time"
  },
  {
    name: "Item 2",
    type: "End Time"
  }
]

Something like so:

<li ng-repeat="item in items | orderBy: type='Start Time'">{{ item.name }}</li>

Is is possible using Angular's orderBy filter?

Any help is appreciated.

3

2 Answers 2

4

No need to specify StartTime,

<li ng-repeat="item in items | orderBy: 'type'>{{ item.name }}</li>

Here is the working Application

1

You only need to specify the key by which you want to order in your orderBy:

orderBy: 'type'

And if you want to reverse the order use -:

orderBy: '-type'
2
  • Will this work even if the data is flipped. And Item 1 has a type of End Time and Item 2 has a type of Start Time
    – realph
    Commented Dec 3, 2015 at 13:44
  • yes, orderBy depends only on the key used to order by Commented Dec 3, 2015 at 13:46

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.