是否可以使用ngoptions而不是ngrepeat将数组绑定到下拉列表

时间:2015-06-19 07:45:07

标签: angularjs angularjs-directive

我无法使用ngOptions将数组绑定到我的下拉列表中。我也无法理解AngularJS文档。

<html ng-app="">

    <body>
        <div class="container" ng-init="numberText=['One', 'Two', 'Three', 'Four', 'Four Plus']">
            <select ng-options="label for schedule in numberText"></select>{{numberText}}</div>
        <select>
            <option ng-repeat="n in numberText">{{n}}</option>
        </select>
    </body>

</html>

我不明白哪些文档试图说明

label for value in array
select as label for value in array
label group by group for value in array
label disable when disable for value in array
label group by group for value in array track by trackexpr
label disable when disable for value in array track by trackexpr
label for value in array | orderBy:orderexpr track by trackexpr (for including a filter with track by)

我正在寻求解释所有这些意味着什么。

Fiddle

1 个答案:

答案 0 :(得分:3)

您需要添加ng-model并将标签更改为像this

这样的arr元素
<select ng-model="test" ng-options="schedule for schedule in numberText"></select>