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.

user990423
  • 1,397
  • 2
  • 12
  • 32
realph
  • 4,481
  • 13
  • 49
  • 104

2 Answers2

4

No need to specify StartTime,

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

Here is the working Application

Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
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'
Tarun Dugar
  • 8,921
  • 8
  • 42
  • 79