I seem to be facing a slight logic issue at the moment.
Currently, I have an accordion with images taken
https://i.sstatic.net/UUs8Y.png
In the HTML, you'll find headers for LIVE BETTING, MLB, MLB Props, and NBA (which is just a snippet of a list containing almost 25 sports)
<accordion>
<accordion-group ng-repeat="sport in sports">
<accordion-heading>
<div ng-click="addSportToLines(sport);">
<span>{{sport.name}}</span>
<span class="badge">{{sport.leagues.length}}</span>
</div>
</accordion-heading>
<div>
<a ng-repeat="league in sport.leagues"
ng-click="addLeagueToLines(league)">
<span>{{league.name}}</span>
<span class="badge">{{league.offeringsAvailable}}</span>
</a>
</div>
</accordion-group>
</accordion>
I need to remove the first <span class=badge>
that displays {{sport.leagues.length}}
and replace it with the sum of all {{league.offeringsAvailable}}
. The number inside the gray badge represents the offeringsAvailable
, which for MLB includes: 72,30,30,8,30
Therefore, instead of displaying sport.leagues.length
in the yellow badge, I want to show the total sum of league.offeringsAvailable
This is the controller for sports
SportsFactory.getSportsWithLeagues().then(function(sports) {
$scope.sports = sports;
console.log(angular.toJson($scope.sports, 'pretty'));
});
The following
console.log(angular.toJson($scope.sports, 'pretty'));
provides this JSON data
Within the JSON structure, headers like LIVE BETTING contain an array of leagues
with a property called offeringsAvailable
. My goal is to extract each individual offeringsAvailable
within a header like LIVE BETTING and calculate the total amount to be stored in a $scope
variable in order to display it in the DOM.
[
{
"id": 26,
"name": "LIVE BETTING",
... (additional data)
},
{
"id": 6,
"name": "MLB",
... (additional data)
},
{
"id": 41,
"name": "MLB Props",
... (additional data)
},
...
I am utilizing LODASH
for iterating over arrays, but I'm unsure how to tackle this specific task
EDIT
Just to clarify, when I mentioned LIVE BETTING earlier, my intention is for the same process to occur for every sport within the array.