我正在尝试显示联赛中球队名称的列表,然后选择一个。选择后,它应该将索引league.teams[index]
放入homeTeam.teamId
。这是HTML:
<select
ng-model="homeTeam.teamId"
ng-options="team.name for team in league.teams">
</select>
这里的范围:
$scope.league = {
teams: [
{ name: "Team#1" },
{ name: "Team#2" }
]
};
但它将整个对象添加到homeTeam.teamId
中,如下所示:
homeTeam: {
"teamId": { "name":"Team#1" }
}
我怎样才能让它只输入索引,即:
homeTeam: {
"teamId": 0
}