I have a little problem with this app that i'm building to learn AngularJs.
It is a Football Stats app. I choose Home Team and Away team from 2 dropdown menus. Then i have to do some math operations and show only the results.
This is my html code:
<div class='dropdown'>
<span>Seleziona Nazione: </span>
<select class='opzioni' ng-model="nazioniSelected">
<option ng-repeat="nazione in nazioni track by $index" value="{{nazione}}">{{nazione}}
</option>
</select>
</div>
<div class='dropdown2'>
<span>Seleziona Campionato: </span>
<select class='opzioni' ng-model="campionatoSelected">
<option ng-repeat="team in teams | filter: {Paese:nazioniSelected} track by $index" value="{{team.Campionato}}">{{team.Campionato}}
</option>
</select>
</div>
<div class='SquadraCasa'>
<span>Seleziona Squadra Casa: </span>
<select class='opzioni' ng-model="HomeTeamSelected" >
<option ng-repeat="team in teams | filter:
{Campionato:campionatoSelected, Paese:nazioniSelected} track by $index"
value='{{team.Nome}}'>
{{team.Nome}}
</option>
</select>
</div>
<div class='SquadraTrasferta'>
<span>Seleziona Squadra Trasferta: </span>
<select class='opzioni' ng-model="AwayTeamSelected">
<option ng-repeat="team in teams | filter:
{Campionato:campionatoSelected, Paese:nazioniSelected} track by $index"
value='{{team.Nome}}'>{{team.Nome}}
</option>
</select>
</div>
<div class='InfoCasa'>
<ul ng-repeat='team in teams | filter: {Nome: HomeTeamSelected} track by $index'>
<img ng-show='HomeTeamSelected' src="{{team.Stemma}} ">
<p class='nome' ng-show='HomeTeamSelected'> {{team.Nome}} </p>
</ul>
</div>
<div class='InfoTrasferta'>
<ul ng-repeat='team in teams | filter: {Nome: AwayTeamSelected} track by $index'>
<img ng-show='AwayTeamSelected' src="{{team.Stemma}} ">
<p class='nome2' ng-show='AwayTeamSelected'> {{team.Nome}} </p>
</ul>
</div>
<div class="Calcolo" ng-show='AwayTeamSelected'>
<p>
Doppia Chance {{doppia}}
</p><br><br>
<p>
1x2
</p><br><br>
<p>
Over 1,5
</p><br><br>
<p>
Over 2,5
</p>
<button class="calcola" ng-click='calcolarisultato(HomeTeamSelected,AwayTeamSelected)' > Calcola
</div>
My problem is: In this ng-click i want to pass not only the name, but all the team variable, because i need all the data about the teams that i selected.
For now my controller is like this and is not working:
FootballNumbers.controller('teamController', function($scope, $route, $routeParams, $http) {
$http.get('/api/teams').then(function(response) {
$scope.teams = response.data;
console.log(response.data);
});
var squadra = $scope.teams;
$scope.nazioni = ['Austria', 'Belgio', 'Bulgaria', 'Croazia', 'Danimarca', 'Finlandia',
'Francia', 'Germania', 'Grecia', 'Inghilterra', 'Italia', 'Norvegia', 'Olanda',
'Polonia', 'Portogallo', 'Rep. Ceca', 'Romania', 'Russia', 'Spagna', 'Turchia', 'Svezia',
'Svizzera', 'Ucraina'
];
$scope.calcolarisultato = function(squadra1, squadra2) {
for (i = 0; i < squadra.length; i++) {
for (j = 0; j < squadra.length; i++) {
if (squadra[i].Nome == squadra1) {
if (squadra[j].Nome == squadra2) {
var media1 = (squadra[i].Classifica + squadra[i].ClassificaCasa +
squadra[i].Forma) / 3;
var media2 = (squadra[j].Classifica + squadra[j].ClassificaTrasferta +
squadra[i].Forma) / 3;
if ((media1 + 3) <= media2) {
$scope.doppia = '1 X';
} else if ((media2 + 3) <= media1) {
$scope.doppia = 'X 2';
} else {
$scope.doppia = 'Niente';
}
}
}
}
}
}
});
It says to me that squadra is not defined.
This is my solution but, as i said, i would like to pass in the function all the HomeTeam and AwayTeam data, not only the name as i did in this code. Any help please?