1. 程式人生 > >ionic中ng-options與默認選中第一項的問題

ionic中ng-options與默認選中第一項的問題

class 設置 -- ctc 添加數據 消失 val 默認選中第一項 route

1. select中動態添加數據時發現一個選項為空,在選中了其他選項時,在點擊時發現第一個空選項消失了,所有我們需要設置一個默認的選項;

2. 開始的時候我用的方法:

<select class="selectcompany" ng-change="change(routeinfo.UnitCode)"  ng-model="routeinfo.UnitCode">
  <option ng-repeat="unit in unitlist" value={{unit.UnitCode}}>{{unit.UnitName}}</option>                    
</select>

  unitlist是 後臺的數據;

發現怎麽設置都不能達到目的;

3. 然後用了這個方法:

<select class="selectcompany" 
           ng-change="change(routeinfo.UnitCode)"  
       ng-model="routeinfo.UnitCode"
       ng-options="unit.UnitCode as unit.UnitName for unit in unitlist">    
</select>

下面寫一個循環後的一個option的樣式:
<option value="unit.UnitCode">unit.UnitName</option>
unit.UnitCode是作為value的值----unit.UnitName
是作為option之間的內容;

此時我們還沒有設置第一項為默認選項:設置方法如下:

在控制器中設置:
$scope.routeinfo.UnitCode=$scope.unitlist[0].UnitCode;

ok就完成了!!!!!!!!

ionic中ng-options與默認選中第一項的問題