我正在使用angular.js和bootstarp - angular-ui-bootstarp。我发现一个问题,当使用select时,即使该选项不为空,在您单击选项列表之前,页面中的选择始终不会显示任何内容。 我尝试的第一件事就是直接在select中添加选项,并使用ng-selected =“selected”创建一个选项,但没有工作
<select class=" input-sm pull-right" style="margin-right: 5px;" ng-change="selectUserFilter()" ng-model="user_filter_key" >
<option >All</option>
<option ng-selected="selected">Active</option>
</select>
我尝试的第二件事是将带有选项列表的模型嵌入到选择中,仍然无法正常工作
$scope.user_options = ['All','Active'];
<select class=" input-sm pull-right" style="margin-right: 5px;" ng-change="selectUserFilter()" ng-model="user_filter_key" ng-options="opt for opt in user_options">
</select>
答案 0 :(得分:2)
请参阅此处http://jsbin.com/tifur/1/edit
只需在控件中设置user_filter键:
$scope.user_filter_key = $scope.user_options[0]
HTML:
<body ng-app="app">
<div ng-controller="firstCtrl">
<select class=" input-sm pull-right" style="margin-right: 5px;" ng-change="selectUserFilter()" ng-model="user_filter_key" ng-options="opt for opt in user_options">
</select>
</div>
</body>
JS:
var app = angular.module('app', []);
app.controller('firstCtrl', function($scope) {
$scope.user_options = ['All', 'Active'];
//add this
$scope.user_filter_key = $scope.user_options[0]
});