【问题标题】:Angular ng-options inside of ng-repeatng-repeat 中的 Angular ng-options
【发布时间】:2013-03-20 16:22:31
【问题描述】:

我无法使用 ng-options 指令将选项元素添加到选择元素。但是我可以使用 ng-repeat 指令来做到这一点。为什么?

HTML,

<div ng-app ng-controller="DescAttrCtrl">
   <div ng-repeat="dattr in dattrs">
        <div ng-repeat="v in dattr.values">
            {{v | json}}
        </div>
        <select name="dattr-{{$index}}" ng-options="v for v in dattr.values">
                <option value=""> --- select a value --- </option>
         <!--   <option ng-repeat="v in dattr.values">{{v}}</option> -->
        </select>
    </div>
</div>

Javascript,

function DescAttrCtrl($scope) {
     $scope.dattrs = [
     {
          "name" : "first attribute",
          "description" : "attribute first description",
          "values" : ["value1", "value2", "value3", "value4"]
     },
     {
          "name" : "second attribute",
          "description" : "attribute second description",
          "values" : ["value1", "value2", "value3", "value4"]
     }
    ];
}

小提琴,http://jsfiddle.net/FwVbC/

【问题讨论】:

  • 你必须指定 ng-model 才能工作

标签: angularjs


【解决方案1】:

请修改如下代码

<select ng-model="selection" ng-options="values for values in dattr.values">
   </select>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-21
    • 1970-01-01
    相关资源
    最近更新 更多