I have an array of an object having 3 properties name
1.name 2.team 3.age
I want group with both age and team.i done group with team but i have confusion how i need to group with both team and age in my current code.
I need to show the age of the team with the team name. Please suggest what should I do?
JS:
$scope.MyList = [
{name: 'Gene', team: 'alpha', age: 19},
{name: 'George', team: 'beta', age: 19},
{name: 'Steve', team: 'gamma', age: 23},
{name: 'Paula', team: 'beta', age: 23},
{name: 'Scruath', team: 'gamma', age: 23},
{name: 'Scruath 1', team: 'gamma', age: 22},
{name: 'Scruath 2', team: 'gamma', age: 22}
];
$scope.getGroups = function () {
var groupArray = [];
angular.forEach($scope.MyList, function (item, idx) {
if (groupArray.indexOf(item.team) == -1){ groupArray.push(item.team)
}
});
return groupArray.sort();
}
HTML:
<div ng-repeat='group in getGroups()'>
<h2>{{group}}</h2>
<ul>
<li ng-repeat="item in MyList | groupby:group">{{item.name}}</li>
</ul>
</div>