AngularJS Tutorial - Filter Sort by date








The following code shows how to use filter sort by date.

Example


<!DOCTYPE html>
<html  ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
</head><!--from w w  w .  ja v  a  2 s  . co m-->
<body>
  <div ng-app>
    <div ng:controller="Main">
      <div ng:repeat="(id, i) in items | orderBy:'date'">{{id}}: {{i.date | date}}</div>
    </div>
</div>
<script type='text/javascript'>
function Main($scope) {
    $scope.items = {
        0: {date: new Date('12/23/2013')},
        1: {date: new Date('12/23/2011')},
        2: {date: new Date('12/23/2010')},
        3: {date: new Date('12/23/2015')}
    };
}
</script>
</body>
</html>

The code above is rendered as follows: