realph
realph

Reputation: 4671

ng-repeat and orderBy a String

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.

Upvotes: 0

Views: 413

Answers (2)

Tarun Dugar
Tarun Dugar

Reputation: 8971

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'

Upvotes: 1

Sajeetharan
Sajeetharan

Reputation: 222682

No need to specify StartTime,

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

Here is the working Application

Upvotes: 4

Related Questions