angular.js select 在开始时不显示选项值 [英] angular.js select doesn't show the option value in the begining
问题描述
我正在使用 angular.js 和 bootstarp - angular-ui-bootstarp.并且发现一个问题,在使用select时,即使选项不为空,页面中的select也总是不显示,直到你点击选项列表.我尝试的第一件事是直接将选项放入选择中,并使用 ng-selected="selected" 创建一个选项,但不起作用
我尝试的第二件事是将带有选项列表的模型嵌入到选择中,但仍然无法正常工作
$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="选择加入 user_options"></选择>
请看这里 http://jsbin.com/tifur/1/edit
只需通过以下方式在您的控制器中设置 user_filter_key :
$scope.user_filter_key = $scope.user_options[0]
html:
<div ng-controller="firstCtrl"><select class="input-sm pull-right" style="margin-right: 5px;"ng-change="selectUserFilter()" ng-model="user_filter_key" ng-options="选择加入 user_options"></选择>
JS:
var app = angular.module('app', []);app.controller('firstCtrl', function($scope) {$scope.user_options = ['All', 'Active'];//添加这个$scope.user_filter_key = $scope.user_options[0]});
I am using angular.js and bootstarp - angular-ui-bootstarp. and I found a problem that when using the select, even the option is not empty, the select in the page always show nothing until you click the option list. The first thing I tried is directly put options in the select, and make one option with ng-selected="selected", but no working
<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>
The second thing I tried is to embedded a model with options list into the select, still not working
$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>
Please see here http://jsbin.com/tifur/1/edit
just set user_filter_key in yyour controler by :
$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]
});
这篇关于angular.js select 在开始时不显示选项值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!