2016-04-04 59 views
0

我有一個下拉選擇使用AngularJS。在控制器中,我從API獲取$ scope.items的值。我想添加value =「0」作爲第一個選項的另一個選項。怎麼做?AngularJS ng選項添加另一個選項

<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

添加選項元素的選擇或將其添加到您的模型

<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> 
+0

我已經試過了,但它沒有工作 – OrgGila

+0

工作對我罰款。哪部分不起作用? –