0

I am trying to group by a set of items inside an array showing the most recent first. I cant figure out what I need. Any help will be appreciate it. I have tried orderby with the minus with no luck.

This is my code and my JSBIN http://jsbin.com/suzokesomo/edit?html,js,output

It groups by Year and Month ascending order 2014, 2015, 2016 . What I want is to display them in descending order 2016, 2015

$scope.Reports = 
[
{ Id: 1, Name: 'Report One', Year: 2016, Month: 5 },
{ Id: 2, Name: 'Report Core', Year: 2016, Month: 5 },
{ Id: 3, Name: 'Report Alpha', Year: 2016, Month: 3 },
{ Id: 4, Name: 'Report Moon', Year: 2014, Month: 5 },
{ Id: 5, Name: 'Report Sky', Year: 2015, Month: 2 }
];

<body>
<div ng-controller="MainController"> 
<ul ng-repeat="(key, value) in Reports | groupBy: 'Year'">
{{ key }}
<ul ng-repeat="(key1, value1) in value | groupBy: 'Month'">
O{{key1}} 
<li ng-repeat="p in value1">
{{p.Name }} 
</li>
</ul>
</ul>
</div>
</body>
Gilberto Quintero
  • 397
  • 1
  • 6
  • 18

0 Answers0