Search code examples
angularjsstringangularjs-orderby

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.


Solution

  • No need to specify StartTime,

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

    Here is the working Application