Considering the structure of my application, I am facing an issue with updating select values in the game form when a team is deleted from the list. Here is how my application is organized:
mainApp
- storageFactory
- userController
- userFactory
- teamController
- teamFactory
- gameController
- gameFactory
Team Form (within teamController)
- select name=player_1
- select name=player_2
- input name=teamname
Game Form (within gameController)
- select name=team_1
- select name=team_2
Currently, if I create a new team, the select scopes in the game form are updated appropriately. However, when a team is deleted, only the scope in the game form selects gets updated. I have been trying to find an efficient way to update the select values in the form if an option was selected before the deletion of the team.
This is the code snippet I am using to iterate through each select value in the game form:
// Check if the first select has a value
var findTeam1 = (scopestor.gamescope.game.hasOwnProperty('team_1')) ? 1 : 0;
// Check if the second select has a value
var findTeam2 = (scopestor.gamescope.game.hasOwnProperty('team_2')) ? 1 : 0;
// Iterate through the updated scope
for(var m in scopestor.gamescope.gameTeamData) {
// Check if the first select has a value and it is in the scope object
if(findTeam1 === 1 && scopestor.gamescope.gameTeamData[m].teamname === scopestor.gamescope.game.team_1.teamname) {
findTeam1 = 2;
}
// Check if the second select has a value and it is in the scope object
if(findTeam2 === 1 && scopestor.gamescope.gameTeamData[m].teamname === scopestor.gamescope.game.team_2.teamname) {
findTeam2 = 2;
}
}
// Check if the first select has a value and not found in the scope
if(findTeam1 === 1) {
// Set the value empty
scopestor.gamescope.game.team_1 = "";
}
// Check if the second select has a value and not found in the scope
if(findTeam2 === 1) {
// Set the value empty
scopestor.gamescope.game.team_2 = "";
}
I'm relatively new to Angular and would appreciate any suggestions or better ways of handling this update of select values in the form.
You can find this code on GitHub: kickertunier-angular for beginners