我有可用的選擇項目的數組:AngularJS - 如何在select中預選值?
// Default available date formats
$scope.dateformats = [
{
code: 'YY.MM.DD',
name: 'YY.MM.DD'
},
{
code: 'DD.MM.YY',
name: 'DD.MM.YY'
}
];
我試圖爲默認預定值是這樣的:
$scope.actualDateformat = $scope.dateformats[0].code;
<select ng-options="dateformat.name for dateformat in dateformats" ng-model="actualDateformat" ng-change="changeDateFormat(dateformat)">
<option style="display:none" value="">{{actualDateformat}}</option>
</select>
的問題是, 「預選」 值出現列表中作爲第一個選項標籤>
<option style="display:none" value="">{{actualDateformat}}</option>
從剩下的兩個動態添加項目中選擇任何一個後,第一個選項中的文本會附加上所選項目的文本(和值)。
請問如何解決?
我想有結果是這樣的:
<select>
<option value="YY.MM.DD">YY.MM.DD</option>
<option value="DD.MM.YY" selected>DD.MM.YY</option>
</select>
感謝您的幫助。
你有沒有試過https:// docs。angularjs.org/api/ng/directive/ngSelected – 2014-10-08 08:29:39