I have another problem that I don't know how to do.
I have a Json with several data and I have to make an average between 2 json data
angular.module('playersApp', []).controller("AllPlayerssCtrl", function ($scope) {
$scope.players = [
{
"stats": [
{
"name": "goals",
"value": 5
},
{
"name": "losses",
"value": 20
},
{
"name": "wins",
"value": 48
},
{
"name": "draws",
"value": 23
},
{
"name": "fwd_pass",
"value": 1533
},
{
"name": "goal_assist",
"value": 2
},
{
"name": "appearances",
"value": 80
},
{
"name": "mins_played",
"value": 6953
},
{
"name": "backward_pass",
"value": 308
}
]
},...];
I have to show the average number of goals per game through the window, that is, divide the value of goals by the value of mins_played and I don't know how to do the function by extracting these values from the json and from there in the ng-if of the html call said function to display the result.
If you can help me please I would appreciate it.
Thank you very much
There are many ways to do it, some more elegant than others, I would use this one that I propose, in which I take the data that interests me from the array, process it, and put the result in a new key.
If tomorrow you need to show some more statistical data, for example assists per minute played, put in the goal_assist switch , do the calculation on it
$scope.players[i].media_asistencia = tmp_goals_assist/tmp_mins
and then paint on the screenjugador.media_asistencia