ng-selected不能与ng-options一起使用,但在ng-repeat下正常工作

Iam使用ng-selectedng-value,ng-options。但我无法选择的价值,ng-selected不工作ng-selected不能与ng-options一起使用,但在ng-repeat下正常工作

<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>

回答:

<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>

回答:

在你的情况,我创建了一个默认值与在选择框中选择做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];

});

select{  

width:150;

}

<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>

以上是 ng-selected不能与ng-options一起使用,但在ng-repeat下正常工作 的全部内容, 来源链接: utcz.com/qa/262511.html

回到顶部