默認option
爲我的select
標記爲空。我希望它是「價值」,而不是。如何在索引的Angular`select`標籤中設置默認`選項`?
這裏是我的plunker:https://plnkr.co/edit/hrcnOCANfzaNEZacQo7R?p=info
爲什麼這個顯示爲空白?我將如何使默認option
標籤讀取「值」並具有value
屬性「值」?
默認option
爲我的select
標記爲空。我希望它是「價值」,而不是。如何在索引的Angular`select`標籤中設置默認`選項`?
這裏是我的plunker:https://plnkr.co/edit/hrcnOCANfzaNEZacQo7R?p=info
爲什麼這個顯示爲空白?我將如何使默認option
標籤讀取「值」並具有value
屬性「值」?
嘗試用一個空白選項:
<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,空白選項將自動被選中。
可以使用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>