2017-04-19 52 views

回答

2

嘗試用一個空白選項:

<select ng-model="customize[$index].selectedDataTransform"> 
    <option value="">Value</option> 
    <option ng-repeat="option in dataTransform" value="{{option.value}}">{{option.label}}</option> 
</select> 

或者用默認值設置ng-model

<select ng-model="customize[$index].selectedDataTransform || 'value'"> 
    <option ng-repeat="option in dataTransform" value="{{option.value}}">{{option.label}}</option> 
</select> 

參考plunker

提到:

如果默認選項的值是空的,當ng-model是unsetted,空白選項將自動被選中。

1

可以使用NG-初始化分配選擇模型

ng-init="customize[$index].selectedDataTransform = dataTransform[0].value"

<select ng-model="customize[$index].selectedDataTransform" ng-init="customize[$index].selectedDataTransform = dataTransform[0].value"> 
    <option ng-repeat="option in dataTransform" value="{{option.value}}">{{option.label}}</option> 
</select> 

Demo

相關問題