How group objects in array from ng-repeat with filter ?
I have an array with objects, and I would like group by this objects by their countries.
Sample : I would like to have this result :
Free : Australia, India, United States
Pay : Australia
Not Pay : Australia, India
from :
$scope.lists = [{
"id": 1
"field": [
{
country: "Australia",
type: "Free"
},
{
country: "Australia",
type: "Pay"
},
{
country: "Australia",
type: "Not Pay"
},
{
country: "India",
type: "Free"
},
{
country: "India",
type: "Not Pay"
},
{
country: "United States",
type: "free"
},
},
{
"id": 2
"field": [
{
country: "Australia",
type: "Pay"
},
{
country: "India",
type: "Free"
},
{
country: "India",
type: "Not Pay"
}
}
]
I tried this with the code :
<div ng-repeat="list in lists">
<ul ng-repeat="(key, value) in list.field | groupBy: 'type'">
{{ key }}
<li ng-repeat="country in value">
: {{ country }}
</li>
</ul>
</div>
Solved :
I use angular 1.4.9 and angular-filter 0.5.7
<div ng-repeat="list in lists">
<ul ng-repeat="(key, value) in list.field | groupBy: 'type'">
{{ key }}
<li ng-repeat="item in value">
: {{ item.country }}
</li>
</ul>
</div>