【问题标题】:how to render the options inside angular select box如何在角度选择框中呈现选项
【发布时间】:2015-07-30 20:25:20
【问题描述】:

如何呈现下拉列表中的值(选择框选项)。 我需要在选择框中显示“header”和“footer”名称。

$scope.sections = [
   {
      "header":{
         "background-color":"#fff",
         "color":"#fff"
      },
      "footer":{
         "background-color":"#fff",
         "color":"#fff"
      }
   }
];

我尝试了以下方式但没有工作,

<select name="section" class="form-control" ng-model ="section">
   <option ng:repeat="options[0] in sections">
        {{options[0]}}
  </option>
</select>

【问题讨论】:

标签: angularjs


【解决方案1】:

您需要遍历键而不是值。

<option ng-repeat="(option, val) in sections[0]">
    {{option}}
</option>

或者使用 ng-options

ng-options="option for (option, val) in sections[0]"

看看那个笨蛋 http://plnkr.co/edit/FQEooL5wNh8Xl8GprT99?p=preview

【讨论】:

  • 完美!。谢谢和+1 :-)。我们如何使用 ng-options 实现相同的目标?有可能吗??
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-23
  • 1970-01-01
  • 2015-04-05
  • 2021-03-14
  • 1970-01-01
  • 2020-12-25
相关资源
最近更新 更多