2015-04-21 54 views
0

當我嘗試下面的代碼:角度值NG選項是使用選擇的標籤語法沒有設置

<select name="test" id="test" ng-model="test" 
    ng-options="c.id as c.n for c in [{n:'t1',id:'123'}]"> 
</select> 

我得到

<select name="test" id="test" ng-model="test" > 
    <option value="0" selected="selected" label="t1">t1</option> 
</select> 

爲什麼值不是「123」每個角的NG -options語法。

謝謝,

+1

它不像在提交表單時被送到了'value'正常的表單字段。 'ng-model'綁定將適當地設置值。見http://plnkr.co/edit/sbGnniTffW9iXT251Gjd?p=preview – Phil

+0

謝謝@菲爾,這是最好的答案... –

回答

0

這是因爲當由ng-options創建通過迭代陣列上的選項,每個選項元素的值是在循環種臺。但是,您的test變量包含值item.age。您可以通過打印{{test}}來檢查它。

你可以達到你想要的東西像這樣

<select name="test" id="test" ng-model="test" > 
<option ng-repeat="c in [{n:'t1',id:'123'}]" value="{{c.id}}" >{{c.n}}</option> 
</select>