AngularJS ng-options增加了另一种选择

时间:2016-04-04 16:25:15

标签: javascript angularjs

我有一个使用AngularJS的下拉选择。在控制器中,我从API获取$ scope.items的值。我想添加另一个选项,其中value =“0”作为第一个选项。怎么做?

<select required class="form-control has-error" id="selected_item"
 ng-options="item.id as item.name for item in items" name="selected_item"
 ng-model="selected_item" ng-change="selectItem()" ng-required="true">
</select>

1 个答案:

答案 0 :(得分:1)

Add an option element to the select or add it to your model

<select required class="form-control has-error" id="selected_item"
 ng-options="item.id as item.name for item in items" name="selected_item"
 ng-model="selected_item" ng-change="selectItem()" ng-required="true">
    <option value="0"></option>
</select>