I have something like this:
<div ng-repeat="i in inv">
<p>{{i.dueDate}}</p>
</div>
I'd like to order by oldest date first. I know there's a way to do it but I can't figure it out. Can anyone help?
Here is the sample js:
$scope.inv = [
{
name: "Paul",
dueDate: "5/21/2014"
},
{
name: "Dan",
dueDate: "5/22/2014"
},
{
name: "Randy",
dueDate: "1/12/2015"
}
];
you need to convert your strings to YYYY-MM-DD format
<li ng-repeat="item in inv | orderBy:orderByDate">{{item.name}} </li>
};
Demo http://plnkr.co/edit/o6fCDyiqkkU9YVWwZC09?p=preview
This should work for you:
You have to define a customizer function, then use it in
orderBy
expression. For example:Demo. The function basically reorders the date string, so that Year comes first, Month next and Day last. If you use
moment.js
or similar library, you can use their parsers instead.