我使用ng-selected
,ng-value
,ng-options
。但我无法选择值ng-selected
无法正常工作
<select name="team_selected"
required="" ng-model="edit_team_name" ng-change="edit_selectTeam(edit_team_name)"
ng-selected='edit_team_id === team.team_id' ng-value="team.team_id"
ng-options="team.team_name for team in teamNameAvailable track by team.team_id">
</select>
答案 0 :(得分:0)
<select name="team_selected" required="" ng-model="edit_team_name" ng-change="edit_selectTeam(edit_team_name)" >
<option ng-repeat="team.team_name for team in teamNameAvailable track by team.team_id" ng-selected='edit_team_id === team.team_id' ng-value="team.team_id"></option
</select>
答案 1 :(得分:0)
在您的情况下,我在选择框
中创建了一个默认值而不是edit_team_id === team.team_id
这个ng-model
本身将选择选择值表格选项
var app = angular.module('testApp',[]);
app.controller('testCtrl',function($scope){
$scope.teamNameAvailable=[{
team_id:1,
team_name:"USA"
},{
team_id:2,
team_name:"India"
},{
team_id:3,
team_name:"Aus"
}];
$scope.edit_team_name=$scope.teamNameAvailable[1];
});
&#13;
select{
width:150;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="testApp" ng-controller="testCtrl">
<select name="team_selected"
required="" ng-model="edit_team_name" ng-change="edit_selectTeam(edit_team_name)"
ng-options="team.team_name for team in teamNameAvailable track by team.team_id">
</select>
</div>
&#13;