angular.js选择不显示在开始时的期权价值 [英] angular.js select doesn't show the option value in the begining
问题描述
我使用angular.js和bootstarp - 角-UI-bootstarp。我发现一个问题,就是使用选择,甚至选项时不为空,在页面中选择总是显示什么,直到你点击选项列表。
我想的第一件事就是直接把选项中选择,并与一个选项NG选择=选择,但没有工作。
<选择类=输入SM右拉式的风格=保证金右:为5px; NG-变化=selectUserFilter()NG模型=user_filter_key>
<选项>所有< /选项>
<选项NG-选择=选择>活动< /选项>
< /选择>
我尝试的第二件事是嵌入选项列表模式进入选择,仍然没有工作。
$ scope.user_options = ['所有','主动'];
<选择类=输入SM右拉式的风格=保证金右:为5px; NG-变化=selectUserFilter()NG模型=user_filter_keyNG选项=选择在user_options选择>
< /选择>
请在这里看到的http:// jsbin .COM / tifur / 1 /编辑
刚刚成立user_filter_key在yyour CONTROLER是:
$ scope.user_filter_key = $ scope.user_options [0]
HTML
<机身NG-应用=应用程序>
< DIV NG控制器=firstCtrl>
<选择类=输入SM右拉式的风格=保证金右:为5px; NG-变化=selectUserFilter()NG模型=user_filter_keyNG选项=选择在user_options选择>
< /选择>
< / DIV>
< /身体GT;
JS:
VAR应用= angular.module('应用',[]);app.controller('firstCtrl',函数($范围){
$ scope.user_options = ['所有','主动'];
//添加此
$ 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选择不显示在开始时的期权价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!