【问题标题】:How can we make the first option value in <select> display by default for values coming dynamically我们如何使 <select> 中的第一个选项值默认显示为动态出现的值
【发布时间】:2017-04-07 10:40:24
【问题描述】:

我有一个字段,它的选项是动态出现的。现在我想默认显示字段中的第一个选项值。有人可以帮忙吗?

<div class="col-lg-4">
 <select name="trader" class="form-control" id="select" ng-model="$root.customerDetails.traderType" 
ng-options="traderTypeObj.description for traderTypeObj in traderTypes track by traderTypeObj.type"  ng-required="true">                  
   </select>
  </div>

谢谢

【问题讨论】:

    标签: html angularjs meteor drop-down-menu html-select


    【解决方案1】:

    您对ng-model 使用了错误的语法。它应该是ng-model="customerDetails.traderType"。删除$root。

    要在选择框中设置默认值,请使用ng-init.ng-init="customerDetails.traderType = traderTypes[0]"

    <select ng-init="somethingHere = options[0]" 
            ng-model="somethingHere" 
            ng-options="option.name for option in options">
    </select>
    

    【讨论】:

      猜你喜欢
      • 2022-08-13
      • 2013-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-29
      • 2012-03-23
      • 1970-01-01
      • 2020-10-24
      相关资源
      最近更新 更多