angular.js选择不显示在开始时的期权价值(angular.js select doesn&#

2019-10-31 03:40发布

我使用angular.js和bootstarp - 角-UI-bootstarp。 我发现了一个问题,即使用选择,甚至选项时不为空,在页面中选择总是显示什么,直到你点击选项列表。 我想的第一件事就是直接把选项中选择,并与NG-选择=“选择”一个选择,但没有工作

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

Answer 1:

请在这里看到http://jsbin.com/tifur/1/edit

刚刚成立user_filter_key由yyour CONTROLER:

 $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 doesn't show the option value in the begining