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就完成了!!!!!!!!