使用ng-options显示对象属性,但使用ng-model绑定索引

时间:2014-04-15 12:16:14

标签: javascript angularjs ng-options angular-ngmodel

我正在尝试显示联盟中球队名称的列表,然后选择一个。选中后,应将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
}

0 个答案:

没有答案