【问题标题】:angular.js select doesn't show the option value in the beginingangularjs select在开始时不显示选项值
【发布时间】:2014-10-04 08:10:02
【问题描述】:

我正在使用 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>

【问题讨论】:

    标签: angularjs angular-ui-bootstrap


    【解决方案1】:

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

    只需在你的控制器中设置 user_filter_key :

     $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]
    
    
    
    });
    

    【讨论】:

    • 谢谢,一个简单的修复,但有很大帮助
    猜你喜欢
    • 2019-07-03
    • 1970-01-01
    • 2014-10-01
    • 1970-01-01
    • 2018-02-12
    • 1970-01-01
    • 2021-03-15
    • 1970-01-01
    • 2018-10-14
    相关资源
    最近更新 更多