2

Im trying to iterate through a collection of teams already belonging to a tournament and want to display them in a select box as preselected values. The teams in the select box come from a team list that have an id association with the tournament teams. I'm sure I'm doing something wrong because not only are the teams not selected but when I change team in one of the drop downs the other two populate the same exact value as well.

I hope my explanation is not to vague. Thanks for your help in advance.

<tbody>
    <tr ng-repeat="team in vm.selectedTournament.teams">

      <td width="130">
        <select name="team" class="form-control" ng-options="team2.name for team2 in vm.teams track by team2.teamid" ng-model="vm.editTeam">

      </td>
      <td>{{ vm.getPlayerName(team.player1).local.fullname }}<br>{{vm.getPlayerName(team.player2).local.fullname}}</td>
      <td class="statDetail">{{team.strength}}</td>
      <td class="statDetail">{{team.PWR}}</td>

    </tr>
  </tbody>
1
  • If anyone can help I would really appreciate it. I might not have been clear what my end objective is and I’m going to try described it again. So if you look at the row in the example above it grabs the 3 teams available in the tournament collection. I want to be able to edit that tournament team section. So for instance if I want to change the team one should be able to list all available teams in the team collection and select a new one for each row if I need to but also the dropdown should have the teams that are currently in the tournament collection selected Commented Mar 10, 2016 at 13:54

1 Answer 1

1

but when I change team in one of the drop downs the other two populate the same exact value as well

It happens because you use same ng-model object for all team rows. Each team row is binds to vm.editTeam.

Give JSON of your teams as sample, I could help you in plunkr. You can fork this one: http://plnkr.co/edit/WVUkCn?p=preview

UPD: Think that's what you want:

(function(angular) {
  'use strict';
  angular.module('teamApp', [])
    .controller('teamController', ['$http', function($http) {
      var vm = this;
      
      vm.tour = {};
      vm.teams = [];
      vm.tourTeams = [];
      
      getTeams();
      fillTourTeams();
      
      function getTeam(id)
      {
        var result = '';
        vm.teams.forEach(function(team){
          if (team.teamid == id)
            result = team;
        });
        
        return result;
      }
      
      function fillTourTeams()
      {
        vm.tour.teams.forEach(function(team, i){
          vm.tourTeams[i] = getTeam(team.teamid);
        });
      }
      
      // --------------------------------------------------
      // LOADING data block
      // --------------------------------------------------
      // sets JSON data to vm.tour & vm.teams
      
      function getTeams()
      {
        vm.tour = {
    "_id" : "56da3700f57a19d92856971b",
    "hide" : false,
    "commissioner" : "5642a4fbf6cb4e0300912c26",
    "name" : "testtornament",
    "playoffs" : true,
    "playoffGames" : [],
    "games" : [],
    "teams" : [ 
        {
            "player2" : "5644d0d7ad80960300ea5347",
            "player1" : "569fa12fcd1cf1030053c876",
            "isselected" : true,
            "name" : "Anaheim Ducks",
            "league" : "NHL",
            "city" : "Anaheim, FL",
            "__v" : 0,
            "teamid" : 1,
            "wins" : 0,
            "PWR" : 0,
            "goalsFor" : 0,
            "goalsAgainst" : 0,
            "strength" : 0,
            "points" : 0,
            "regulationOvertimeWins" : 0,
            "gamesPlayed" : 0,
            "goalDifferential" : 0,
            "shootoutWins" : 0,
            "overtimeShootoutLosses" : 0,
            "shootoutLosses" : 0,
            "regulationLosses" : 0,
            "_id" : "56b91258f5ccff0300b8be26"
        }, 
        {
            "player2" : "564294d6556a120300047078",
            "player1" : "5661eb3455814e030034fd3a",
            "isselected" : true,
            "name" : "Arizona Coyotes",
            "league" : "NHL",
            "city" : "Glendale , AZ",
            "__v" : 0,
            "teamid" : 4,
            "wins" : 0,
            "PWR" : 0,
            "goalsFor" : 0,
            "goalsAgainst" : 0,
            "strength" : 0,
            "points" : 0,
            "regulationOvertimeWins" : 0,
            "gamesPlayed" : 0,
            "goalDifferential" : 0,
            "shootoutWins" : 0,
            "overtimeShootoutLosses" : 0,
            "shootoutLosses" : 0,
            "regulationLosses" : 0,
            "_id" : "56b912eff5ccff0300b8be27"
        }, 
        {
            "player2" : "5642a4fbf6cb4e0300912c26",
            "player1" : "564604ead0ffe80300ee3806",
            "isselected" : true,
            "name" : "Boston Bruins",
            "league" : "NHL",
            "city" : "Boston, MA",
            "__v" : 0,
            "teamid" : 2,
            "wins" : 0,
            "PWR" : 0,
            "goalsFor" : 0,
            "goalsAgainst" : 0,
            "strength" : 0,
            "points" : 0,
            "regulationOvertimeWins" : 0,
            "gamesPlayed" : 0,
            "goalDifferential" : 0,
            "shootoutWins" : 0,
            "overtimeShootoutLosses" : 0,
            "shootoutLosses" : 0,
            "regulationLosses" : 0,
            "_id" : "56b91348f5ccff0300b8be28"
        }, 
        {
            "player2" : "5694273f1012bf030046e5b7",
            "player1" : "5627f66b7146710300e9281f",
            "isselected" : true,
            "name" : "Buffalo Sabres",
            "league" : "NHL",
            "city" : "Buffalo, NY",
            "__v" : 0,
            "teamid" : 3,
            "wins" : 0,
            "PWR" : 0,
            "goalsFor" : 0,
            "goalsAgainst" : 0,
            "strength" : 0,
            "points" : 0,
            "regulationOvertimeWins" : 0,
            "gamesPlayed" : 0,
            "goalDifferential" : 0,
            "shootoutWins" : 0,
            "overtimeShootoutLosses" : 0,
            "shootoutLosses" : 0,
            "regulationLosses" : 0,
            "_id" : "56b91370f5ccff0300b8be29"
        }, 
        {
            "player2" : "564e460bf3ec410300e1d599",
            "player1" : "564f899642a34c0300a8e6a8",
            "isselected" : true,
            "name" : "Calgary Flames",
            "league" : "NHL",
            "city" : "Calgary, AB",
            "__v" : 0,
            "teamid" : 5,
            "wins" : 0,
            "PWR" : 0,
            "goalsFor" : 0,
            "goalsAgainst" : 0,
            "strength" : 0,
            "points" : 0,
            "regulationOvertimeWins" : 0,
            "gamesPlayed" : 0,
            "goalDifferential" : 0,
            "shootoutWins" : 0,
            "overtimeShootoutLosses" : 0,
            "shootoutLosses" : 0,
            "regulationLosses" : 0,
            "_id" : "56b913ccf5ccff0300b8be2a"
        }, 
        {
            "player2" : "56620a9559749f030064f9d8",
            "player1" : "56ba9add45e99567ba637502",
            "isselected" : true,
            "name" : "Carolina Hurricanes",
            "league" : "NHL",
            "city" : "Raleigh, NC",
            "__v" : 0,
            "teamid" : 6,
            "wins" : 0,
            "PWR" : 0,
            "goalsFor" : 0,
            "goalsAgainst" : 0,
            "strength" : 0,
            "points" : 0,
            "regulationOvertimeWins" : 0,
            "gamesPlayed" : 0,
            "goalDifferential" : 0,
            "shootoutWins" : 0,
            "overtimeShootoutLosses" : 0,
            "shootoutLosses" : 0,
            "regulationLosses" : 0,
            "_id" : "56b913fff5ccff0300b8be2b"
        }
    ],
    "__v" : 0
};
        vm.teams = [
{
    "regulationLosses" : 0,
    "shootoutLosses" : 0,
    "overtimeShootoutLosses" : 0,
    "shootoutWins" : 0,
    "goalDifferential" : 0,
    "gamesPlayed" : 0,
    "regulationOvertimeWins" : 0,
    "points" : 0,
    "strength" : 0,
    "goalsAgainst" : 0,
    "goalsFor" : 0,
    "PWR" : 1,
    "wins" : 0,
    "teamid" : 32,
    "league" : "IWC",
    "city" : "Czech Republic",
    "name" : "Team Czech Republic",
    "__v" : 0
},
{
    "regulationLosses" : 0,
    "shootoutLosses" : 0,
    "overtimeShootoutLosses" : 0,
    "shootoutWins" : 0,
    "goalDifferential" : 0,
    "gamesPlayed" : 0,
    "regulationOvertimeWins" : 0,
    "points" : 0,
    "strength" : 0,
    "goalsAgainst" : 0,
    "goalsFor" : 0,
    "PWR" : 3,
    "wins" : 0,
    "teamid" : 9,
    "__v" : 0,
    "city" : "Columbus, OH",
    "league" : "NHL",
    "name" : "Columbus Blue Jackets"
},
{
    "regulationLosses" : 0,
    "shootoutLosses" : 0,
    "overtimeShootoutLosses" : 0,
    "shootoutWins" : 0,
    "goalDifferential" : 0,
    "gamesPlayed" : 0,
    "regulationOvertimeWins" : 0,
    "points" : 0,
    "strength" : 0,
    "goalsAgainst" : 0,
    "goalsFor" : 0,
    "PWR" : 6,
    "wins" : 0,
    "teamid" : 15,
    "__v" : 0,
    "city" : "Los Angeles, CA",
    "league" : "NHL",
    "name" : "Los Angeles Kings"
},
{ 
    "regulationLosses" : 0,
    "shootoutLosses" : 0,
    "overtimeShootoutLosses" : 0,
    "shootoutWins" : 0,
    "goalDifferential" : 0,
    "gamesPlayed" : 0,
    "regulationOvertimeWins" : 0,
    "points" : 0,
    "strength" : 0,
    "goalsAgainst" : 0,
    "goalsFor" : 0,
    "PWR" : 10,
    "wins" : 0,
    "teamid" : 16,
    "__v" : 0,
    "city" : "Nashville, TN",
    "league" : "NHL",
    "name" : "Nashville Predators"
},


{
   
    "regulationLosses" : 0,
    "shootoutLosses" : 0,
    "overtimeShootoutLosses" : 0,
    "shootoutWins" : 0,
    "goalDifferential" : 0,
    "gamesPlayed" : 0,
    "regulationOvertimeWins" : 0,
    "points" : 0,
    "strength" : 0,
    "goalsAgainst" : 0,
    "goalsFor" : 0,
    "PWR" : 20,
    "wins" : 0,
    "teamid" : 20,
    "__v" : 0,
    "city" : "Philadelphia, PA",
    "league" : "NHL",
    "name" : "Philadelphia Flyers"
},


{
   
    "regulationLosses" : 0,
    "shootoutLosses" : 0,
    "overtimeShootoutLosses" : 0,
    "shootoutWins" : 0,
    "goalDifferential" : 0,
    "gamesPlayed" : 0,
    "regulationOvertimeWins" : 0,
    "points" : 0,
    "strength" : 0,
    "goalsAgainst" : 0,
    "goalsFor" : 0,
    "PWR" : 10,
    "wins" : 0,
    "teamid" : 22,
    "__v" : 0,
    "city" : "Montreal, Quebec",
    "league" : "NHL",
    "name" : "Montréal Canadiens"
},


{
   
    "regulationLosses" : 0,
    "shootoutLosses" : 0,
    "overtimeShootoutLosses" : 0,
    "shootoutWins" : 0,
    "goalDifferential" : 0,
    "gamesPlayed" : 0,
    "regulationOvertimeWins" : 0,
    "points" : 0,
    "strength" : 0,
    "goalsAgainst" : 0,
    "goalsFor" : 0,
    "PWR" : 8,
    "wins" : 0,
    "teamid" : 23,
    "__v" : 0,
    "city" : "Pittsburgh, PA",
    "league" : "NHL",
    "name" : "Pittsburgh Penguins"
},


{
   
    "regulationLosses" : 0,
    "shootoutLosses" : 0,
    "overtimeShootoutLosses" : 0,
    "shootoutWins" : 0,
    "goalDifferential" : 0,
    "gamesPlayed" : 0,
    "regulationOvertimeWins" : 0,
    "points" : 0,
    "strength" : 0,
    "goalsAgainst" : 0,
    "goalsFor" : 0,
    "PWR" : 18,
    "wins" : 0,
    "teamid" : 27,
    "__v" : 0,
    "city" : "Toronto, Ontario",
    "league" : "NHL",
    "name" : "Toronto Maple Leafs"
},


{
   
    "regulationLosses" : 0,
    "shootoutLosses" : 0,
    "overtimeShootoutLosses" : 0,
    "shootoutWins" : 0,
    "goalDifferential" : 0,
    "gamesPlayed" : 0,
    "regulationOvertimeWins" : 0,
    "points" : 0,
    "strength" : 0,
    "goalsAgainst" : 0,
    "goalsFor" : 0,
    "PWR" : 11,
    "wins" : 0,
    "teamid" : 29,
    "__v" : 0,
    "city" : "Washington, DC",
    "league" : "NHL",
    "name" : "Washington Capitals"
},


{
   
    "regulationLosses" : 0,
    "shootoutLosses" : 0,
    "overtimeShootoutLosses" : 0,
    "shootoutWins" : 0,
    "goalDifferential" : 0,
    "gamesPlayed" : 0,
    "regulationOvertimeWins" : 0,
    "points" : 0,
    "strength" : 0,
    "goalsAgainst" : 0,
    "goalsFor" : 0,
    "PWR" : 12,
    "wins" : 0,
    "teamid" : 30,
    "__v" : 0,
    "city" : "Winnipeg, Manitoba",
    "league" : "NHL",
    "name" : "Winnipeg Jets"
},


{
   
    "regulationLosses" : 0,
    "shootoutLosses" : 0,
    "overtimeShootoutLosses" : 0,
    "shootoutWins" : 0,
    "goalDifferential" : 0,
    "gamesPlayed" : 0,
    "regulationOvertimeWins" : 0,
    "points" : 0,
    "strength" : 0,
    "goalsAgainst" : 0,
    "goalsFor" : 0,
    "PWR" : 13,
    "wins" : 0,
    "teamid" : 28,
    "__v" : 0,
    "city" : "Vancouver, British Columbia",
    "league" : "NHL",
    "name" : "Vancouver Canucks"
},

{
   
    "regulationLosses" : 0,
    "shootoutLosses" : 0,
    "overtimeShootoutLosses" : 0,
    "shootoutWins" : 0,
    "goalDifferential" : 0,
    "gamesPlayed" : 0,
    "regulationOvertimeWins" : 0,
    "points" : 0,
    "strength" : 0,
    "goalsAgainst" : 0,
    "goalsFor" : 0,
    "PWR" : 14,
    "wins" : 0,
    "teamid" : 26,
    "__v" : 0,
    "city" : "Tampa, FL",
    "league" : "NHL",
    "name" : "Tampa Bay Lightning"
},


{
   
    "regulationLosses" : 0,
    "shootoutLosses" : 0,
    "overtimeShootoutLosses" : 0,
    "shootoutWins" : 0,
    "goalDifferential" : 0,
    "gamesPlayed" : 0,
    "regulationOvertimeWins" : 0,
    "points" : 0,
    "strength" : 0,
    "goalsAgainst" : 0,
    "goalsFor" : 0,
    "PWR" : 15,
    "wins" : 0,
    "teamid" : 25,
    "__v" : 0,
    "city" : "St. Louis, MO",
    "league" : "NHL",
    "name" : "St. Louis Blues"
},


{
   
    "regulationLosses" : 0,
    "shootoutLosses" : 0,
    "overtimeShootoutLosses" : 0,
    "shootoutWins" : 0,
    "goalDifferential" : 0,
    "gamesPlayed" : 0,
    "regulationOvertimeWins" : 0,
    "points" : 0,
    "strength" : 0,
    "goalsAgainst" : 0,
    "goalsFor" : 0,
    "PWR" : 16,
    "wins" : 0,
    "teamid" : 24,
    "__v" : 0,
    "city" : "San Jose, CA",
    "league" : "NHL",
    "name" : "San Jose Sharks"
},


{
   
    "regulationLosses" : 0,
    "shootoutLosses" : 0,
    "overtimeShootoutLosses" : 0,
    "shootoutWins" : 0,
    "goalDifferential" : 0,
    "gamesPlayed" : 0,
    "regulationOvertimeWins" : 0,
    "points" : 0,
    "strength" : 0,
    "goalsAgainst" : 0,
    "goalsFor" : 0,
    "PWR" : 17,
    "wins" : 0,
    "teamid" : 21,
    "__v" : 0,
    "city" : "Ottawa, Ontario",
    "league" : "NHL",
    "name" : "Ottawa Senators"
},
{
    "regulationLosses" : 0,
    "shootoutLosses" : 0,
    "overtimeShootoutLosses" : 0,
    "shootoutWins" : 0,
    "goalDifferential" : 0,
    "gamesPlayed" : 0,
    "regulationOvertimeWins" : 0,
    "points" : 0,
    "strength" : 0,
    "goalsAgainst" : 0,
    "goalsFor" : 0,
    "PWR" : 11,
    "wins" : 0,
    "teamid" : 19,
    "__v" : 0,
    "city" : "New York, NY",
    "league" : "NHL",
    "name" : "New York Rangers"
},
{
    "regulationLosses" : 0,
    "shootoutLosses" : 0,
    "overtimeShootoutLosses" : 0,
    "shootoutWins" : 0,
    "goalDifferential" : 0,
    "gamesPlayed" : 0,
    "regulationOvertimeWins" : 0,
    "points" : 0,
    "strength" : 0,
    "goalsAgainst" : 0,
    "goalsFor" : 0,
    "PWR" : 11,
    "wins" : 0,
    "teamid" : 18,
    "__v" : 0,
    "city" : "Brooklyn, NY",
    "league" : "NHL",
    "name" : "New York Islanders"
},
{
    "regulationLosses" : 0,
    "shootoutLosses" : 0,
    "overtimeShootoutLosses" : 0,
    "shootoutWins" : 0,
    "goalDifferential" : 0,
    "gamesPlayed" : 0,
    "regulationOvertimeWins" : 0,
    "points" : 0,
    "strength" : 0,
    "goalsAgainst" : 0,
    "goalsFor" : 0,
    "PWR" : 11,
    "wins" : 0,
    "teamid" : 14,
    "__v" : 0,
    "city" : "St. Paul, MN",
    "league" : "NHL",
    "name" : "Minnesota Wild"
},
{
    "regulationLosses" : 0,
    "shootoutLosses" : 0,
    "overtimeShootoutLosses" : 0,
    "shootoutWins" : 0,
    "goalDifferential" : 0,
    "gamesPlayed" : 0,
    "regulationOvertimeWins" : 0,
    "points" : 0,
    "strength" : 0,
    "goalsAgainst" : 0,
    "goalsFor" : 0,
    "PWR" : 11,
    "wins" : 0,
    "teamid" : 17,
    "__v" : 0,
    "city" : "Newark, NJ",
    "league" : "NHL",
    "name" : "New Jersey Devils"
},
{
    "regulationLosses" : 0,
    "shootoutLosses" : 0,
    "overtimeShootoutLosses" : 0,
    "shootoutWins" : 0,
    "goalDifferential" : 0,
    "gamesPlayed" : 0,
    "regulationOvertimeWins" : 0,
    "points" : 0,
    "strength" : 0,
    "goalsAgainst" : 0,
    "goalsFor" : 0,
    "PWR" : 11,
    "wins" : 0,
    "teamid" : 13,
    "__v" : 0,
    "city" : "Detroit, MI",
    "league" : "NHL",
    "name" : "Detroit Red Wings"
},
{
    "regulationLosses" : 0,
    "shootoutLosses" : 0,
    "overtimeShootoutLosses" : 0,
    "shootoutWins" : 0,
    "goalDifferential" : 0,
    "gamesPlayed" : 0,
    "regulationOvertimeWins" : 0,
    "points" : 0,
    "strength" : 0,
    "goalsAgainst" : 0,
    "goalsFor" : 0,
    "PWR" : 11,
    "wins" : 0,
    "teamid" : 12,
    "__v" : 0,
    "city" : "Sunrise, FL",
    "league" : "NHL",
    "name" : "Florida Panthers"
},
{
    "regulationLosses" : 0,
    "shootoutLosses" : 0,
    "overtimeShootoutLosses" : 0,
    "shootoutWins" : 0,
    "goalDifferential" : 0,
    "gamesPlayed" : 0,
    "regulationOvertimeWins" : 0,
    "points" : 0,
    "strength" : 0,
    "goalsAgainst" : 0,
    "goalsFor" : 0,
    "PWR" : 11,
    "wins" : 0,
    "teamid" : 11,
    "__v" : 0,
    "city" : "Edmonton, AB",
    "league" : "NHL",
    "name" : "Edmonton Oilers"
},
{
    "regulationLosses" : 0,
    "shootoutLosses" : 0,
    "overtimeShootoutLosses" : 0,
    "shootoutWins" : 0,
    "goalDifferential" : 0,
    "gamesPlayed" : 0,
    "regulationOvertimeWins" : 0,
    "points" : 0,
    "strength" : 0,
    "goalsAgainst" : 0,
    "goalsFor" : 0,
    "PWR" : 11,
    "wins" : 0,
    "teamid" : 10,
    "__v" : 0,
    "city" : "Dallas, TX",
    "league" : "NHL",
    "name" : "Dallas Stars"
},
{
   
    "regulationLosses" : 0,
    "shootoutLosses" : 0,
    "overtimeShootoutLosses" : 0,
    "shootoutWins" : 0,
    "goalDifferential" : 0,
    "gamesPlayed" : 0,
    "regulationOvertimeWins" : 0,
    "points" : 0,
    "strength" : 0,
    "goalsAgainst" : 0,
    "goalsFor" : 0,
    "PWR" : 11,
    "wins" : 0,
    "teamid" : 8,
    "__v" : 0,
    "city" : "Denver, CO",
    "league" : "NHL",
    "name" : "Colorado Avalanche"
},
{
    "regulationLosses" : 0,
    "shootoutLosses" : 0,
    "overtimeShootoutLosses" : 0,
    "shootoutWins" : 0,
    "goalDifferential" : 0,
    "gamesPlayed" : 0,
    "regulationOvertimeWins" : 0,
    "points" : 0,
    "strength" : 0,
    "goalsAgainst" : 0,
    "goalsFor" : 0,
    "PWR" : 11,
    "wins" : 0,
    "teamid" : 7,
    "__v" : 0,
    "city" : "Chicago, IL",
    "league" : "NHL",
    "name" : "Chicago Blackhawks"
},
{
    "regulationLosses" : 0,
    "shootoutLosses" : 0,
    "overtimeShootoutLosses" : 0,
    "shootoutWins" : 0,
    "goalDifferential" : 0,
    "gamesPlayed" : 0,
    "regulationOvertimeWins" : 0,
    "points" : 0,
    "strength" : 0,
    "goalsAgainst" : 0,
    "goalsFor" : 0,
    "PWR" : 11,
    "wins" : 0,
    "teamid" : 6,
    "__v" : 0,
    "city" : "Raleigh, NC",
    "league" : "NHL",
    "name" : "Carolina Hurricanes"
},
{
    "regulationLosses" : 0,
    "shootoutLosses" : 0,
    "overtimeShootoutLosses" : 0,
    "shootoutWins" : 0,
    "goalDifferential" : 0,
    "gamesPlayed" : 0,
    "regulationOvertimeWins" : 0,
    "points" : 0,
    "strength" : 0,
    "goalsAgainst" : 0,
    "goalsFor" : 0,
    "PWR" : 40,
    "wins" : 0,
    "teamid" : 5,
    "__v" : 0,
    "city" : "Calgary, AB",
    "league" : "NHL",
    "name" : "Calgary Flames"
},
{
    "regulationLosses" : 0,
    "shootoutLosses" : 0,
    "overtimeShootoutLosses" : 0,
    "shootoutWins" : 0,
    "goalDifferential" : 0,
    "gamesPlayed" : 0,
    "regulationOvertimeWins" : 0,
    "points" : 0,
    "strength" : 0,
    "goalsAgainst" : 0,
    "goalsFor" : 0,
    "PWR" : 61,
    "wins" : 0,
    "teamid" : 4,
    "__v" : 0,
    "city" : "Glendale , AZ",
    "league" : "NHL",
    "name" : "Arizona Coyotes"
},
{
   
    "regulationLosses" : 0,
    "shootoutLosses" : 0,
    "overtimeShootoutLosses" : 0,
    "shootoutWins" : 0,
    "goalDifferential" : 0,
    "gamesPlayed" : 0,
    "regulationOvertimeWins" : 0,
    "points" : 0,
    "strength" : 0,
    "goalsAgainst" : 0,
    "goalsFor" : 0,
    "PWR" : 51,
    "wins" : 0,
    "teamid" : 3,
    "__v" : 0,
    "city" : "Buffalo, NY",
    "league" : "NHL",
    "name" : "Buffalo Sabres"
},
{
   
    "regulationLosses" : 0,
    "shootoutLosses" : 0,
    "overtimeShootoutLosses" : 0,
    "shootoutWins" : 0,
    "goalDifferential" : 0,
    "gamesPlayed" : 0,
    "regulationOvertimeWins" : 0,
    "points" : 0,
    "strength" : 0,
    "goalsAgainst" : 0,
    "goalsFor" : 0,
    "PWR" : 18,
    "wins" : 0,
    "teamid" : 2,
    "__v" : 0,
    "city" : "Boston, MA",
    "league" : "NHL",
    "name" : "Boston Bruins"
},
{
   
    "regulationLosses" : 0,
    "shootoutLosses" : 0,
    "overtimeShootoutLosses" : 0,
    "shootoutWins" : 0,
    "goalDifferential" : 0,
    "gamesPlayed" : 0,
    "regulationOvertimeWins" : 0,
    "points" : 0,
    "strength" : 0,
    "goalsAgainst" : 0,
    "goalsFor" : 0,
    "PWR" : 110,
    "wins" : 0,
    "teamid" : 1,
    "__v" : 0,
    "city" : "Anaheim, FL",
    "league" : "NHL",
    "name" : "Anaheim Ducks"
}
];
      }
      // --------------------------------------------------
      // LOADING data block end
      // --------------------------------------------------

    }]);
})(window.angular);
body
{
  padding: 20px;
}
<!doctype html>
<html lang="en">
<head>
  <title>Teams - AngularJS sample for ngRepeat/ngSelect</title>
  <meta charset="UTF-8">
  
  <!-- AngularJS -->
  <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js"></script>
  <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular-animate.js"></script>
  <!-- Bootstrap -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" >
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" >
  
  <script src="script.js"></script>
  <link href="style.css" rel="stylesheet" type="text/css">
  
</head>
<body ng-app="teamApp">
  
  <div ng-controller="teamController as vm">
  
  <div class="panel panel-default">

    <div class="panel-heading">
      Teams ({{vm.teams.length}})
    </div>
    
    <table class="table table-hover">
      <thead><tr>
          <th>ID</th>
          <th>Team name</th>
          <th>Players</th>
          <th>ST</th>
          <th>PWR</th>
      </tr></thead>
      <tbody>
        <tr ng-repeat="team in vm.tour.teams">
          
          <td>{{vm.tourTeams[$index].teamid}}</td>
          <td>
            <select ng-options="team.name for team in vm.teams" ng-model="vm.tourTeams[$index]">
            </select>
          </td>
          <td>-</td>
          <td>{{vm.tourTeams[$index].strength}}</td>
          <td>{{vm.tourTeams[$index].PWR}}</td>
          
        </tr>
      </tbody>
    </table>
  </div>
  
</div>
</body>
</html>

Same code in plnkr: http://plnkr.co/edit/wslwQP?p=preview

Sign up to request clarification or add additional context in comments.

6 Comments

Here is the forked version with the teams.json file plnkr.co/edit/3SfUSJBK9wy5CZeLgRH3?p=preview thank you!
I also added the tournament.json file so you can see the selected teams in the tournament.
Let me try, for a moment
Sth hard with data logic. Add me in skype if you wish: dab_den
Ok I can try to do that later. When looking at the plunkr doc you are selecting the category by hardcoding it. In my scenario the preselected teams should come from the tournament teams array in the tournament.json file. There are 6 teams with teamid. I would like the drop down to pull the teams from the teams.json file and display the selected team by matching the teamid in the torunament.json. This would allow me to change team if I need to. Not sure if this makes any sense to you.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.