My goal is to print an object using ng-repeat but knowing that some keys are repeated. I want it to be printed once only if this case and I want to calculate the average of its similar values.
This is my data.
[
{
"0":"1",
"1":"Creativity",
"2":"5",
"3":"1",
"4":"2017-01-17 21:24:42",
"5":"ratings",
"6":null,
"ID":"1",
"Title":"Creativity",
"Value":"5",
"Parent":"1",
"Timestamp":"2017-01-17 21:24:42",
"Category":"ratings",
"Author":null
},
{
"0":"2",
"1":"Courage",
"2":"4",
"3":"1",
"4":"2017-01-17 21:24:42",
"5":"ratings",
"6":null,
"ID":"2",
"Title":"Courage",
"Value":"4",
"Parent":"1",
"Timestamp":"2017-01-17 21:24:42",
"Category":"ratings",
"Author":null
},
{
"0":"3",
"1":"Honnesty",
"2":"4",
"3":"1",
"4":"2017-01-17 21:24:42",
"5":"ratings",
"6":null,
"ID":"3",
"Title":"Honnesty",
"Value":"4",
"Parent":"1",
"Timestamp":"2017-01-17 21:24:42",
"Category":"ratings",
"Author":null
},
{
"0":"4",
"1":"Ambition",
"2":"3",
"3":"1",
"4":"2017-01-17 21:24:42",
"5":"ratings",
"6":null,
"ID":"4",
"Title":"Ambition",
"Value":"3",
"Parent":"1",
"Timestamp":"2017-01-17 21:24:42",
"Category":"ratings",
"Author":null
},
{
"0":"5",
"1":"Integrity",
"2":"4",
"3":"1",
"4":"2017-01-17 21:24:42",
"5":"ratings",
"6":null,
"ID":"5",
"Title":"Integrity",
"Value":"4",
"Parent":"1",
"Timestamp":"2017-01-17 21:24:42",
"Category":"ratings",
"Author":null
},
{
"0":"165",
"1":"Creativity",
"2":"4",
"3":"1",
"4":"2017-01-20 21:12:25",
"5":"ratings",
"6":"18",
"ID":"165",
"Title":"Creativity",
"Value":"4",
"Parent":"1",
"Timestamp":"2017-01-20 21:12:25",
"Category":"ratings",
"Author":"18"
},
{
"0":"166",
"1":"Courage",
"2":"4",
"3":"1",
"4":"2017-01-20 21:12:25",
"5":"ratings",
"6":"18",
"ID":"166",
"Title":"Courage",
"Value":"4",
"Parent":"1",
"Timestamp":"2017-01-20 21:12:25",
"Category":"ratings",
"Author":"18"
},
{
"0":"167",
"1":"Honnesty",
"2":"2",
"3":"1",
"4":"2017-01-20 21:12:25",
"5":"ratings",
"6":"18",
"ID":"167",
"Title":"Honnesty",
"Value":"2",
"Parent":"1",
"Timestamp":"2017-01-20 21:12:25",
"Category":"ratings",
"Author":"18"
},
{
"0":"168",
"1":"Ambition",
"2":"3",
"3":"1",
"4":"2017-01-20 21:12:25",
"5":"ratings",
"6":"18",
"ID":"168",
"Title":"Ambition",
"Value":"3",
"Parent":"1",
"Timestamp":"2017-01-20 21:12:25",
"Category":"ratings",
"Author":"18"
},
{
"0":"169",
"1":"Integrity",
"2":"2",
"3":"1",
"4":"2017-01-20 21:12:25",
"5":"ratings",
"6":"18",
"ID":"169",
"Title":"Integrity",
"Value":"2",
"Parent":"1",
"Timestamp":"2017-01-20 21:12:25",
"Category":"ratings",
"Author":"18"
},
{
"0":"170",
"1":"Creativity",
"2":"4",
"3":"1",
"4":"2017-01-20 21:16:53",
"5":"ratings",
"6":"18",
"ID":"170",
"Title":"Creativity",
"Value":"4",
"Parent":"1",
"Timestamp":"2017-01-20 21:16:53",
"Category":"ratings",
"Author":"18"
},
{
"0":"171",
"1":"Courage",
"2":"4",
"3":"1",
"4":"2017-01-20 21:16:53",
"5":"ratings",
"6":"18",
"ID":"171",
"Title":"Courage",
"Value":"4",
"Parent":"1",
"Timestamp":"2017-01-20 21:16:53",
"Category":"ratings",
"Author":"18"
},
{
"0":"172",
"1":"Honnesty",
"2":"5",
"3":"1",
"4":"2017-01-20 21:16:53",
"5":"ratings",
"6":"18",
"ID":"172",
"Title":"Honnesty",
"Value":"5",
"Parent":"1",
"Timestamp":"2017-01-20 21:16:53",
"Category":"ratings",
"Author":"18"
},
{
"0":"173",
"1":"Ambition",
"2":"3",
"3":"1",
"4":"2017-01-20 21:16:53",
"5":"ratings",
"6":"18",
"ID":"173",
"Title":"Ambition",
"Value":"3",
"Parent":"1",
"Timestamp":"2017-01-20 21:16:53",
"Category":"ratings",
"Author":"18"
},
{
"0":"174",
"1":"Integrity",
"2":"5",
"3":"1",
"4":"2017-01-20 21:16:53",
"5":"ratings",
"6":"18",
"ID":"174",
"Title":"Integrity",
"Value":"5",
"Parent":"1",
"Timestamp":"2017-01-20 21:16:53",
"Category":"ratings",
"Author":"18"
}
]
This is my html
<h3>Overall Ratings: {{ getTotal() }}</h3>
<div class="row">
<div class="container">
<table class="table table-hover">
<thead>
<tr>
<th>Label</th>
<th>Rate</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="profile in data | filter:searchFilter">
<td>{{profile.Title}}</td>
<td>{{profile.Value}}</td>
</tr>
</tbody>
</table>
</div>
</div>
The problem is that the output is like this:
The output should be like this:
[{
"Value": 4.25,
"Title": "Creativity",
},
{
"Value": 2.7,
"Title": "Courage",
},
{
"Value": 3.33,
"Title": "Honnesty",
}, {
"Value": 4.5,
"Title": "Ambition",
}, {
"Value": 5,
"Title": "Integrity",
}
];

ng-repeat.