你好,我有同样的问题
我有这样奇怪的选择
<option value="? string:98 ?"></option>
HTML代码
<select ng-model="vm.student" class="form-control">
<option value="0">All</option>
<option data-ng-repeat="src in vm.studentList" value="{{ src.Id }}"> {{
src.Value }} </option>
</select>
默认值没有出现在底部,我正在尝试多种方法来解决此问题,但不幸的是,这种方法无法正常工作
我希望能帮助我解决此问题
谢谢
答案 0 :(得分:0)
使用ng-value
指令:
<select ng-model="vm.student" class="form-control">
<option ng-value="0">All</option>
<option data-ng-repeat="src in vm.studentList" ng-value="src.Id">
{{src.Value}}
</option>
</select>
有关更多信息,
答案 1 :(得分:0)
可以使用ng-options来解决
通过引用 Madhan Varadhodiyil 示例
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp">
<div ng-controller="AppCtrl">
<select ng-model="student" class="form-control" ng-options="src.Id as src.Value for src in studentList">
<option value="">All</option> <!-- value="" helps to remove void space from dropdown -->
</select>
</div>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('AppCtrl', function($scope){
$scope.studentList = [
{
"Id": 98,
"Value": "Jon Snow"
},
{
"Id": 99,
"Value": "Mother of dragons"
}
];
$scope.student = $scope.studentList[0].Id; // I want Id:98 to be selected by default
});</script>
希望会有所帮助,干杯!