我正在使用ng-repeat創建出生日期選擇器下拉菜單。我面臨的問題是我想將選項作爲DD附加到日期,作爲第一個元素的MM作爲月份,YYYY作爲下拉的年份。下面是我使用的下拉創建coode創建出生日期使用ng-repeat使用下拉硬編碼中的第一個元素的下拉菜單
<div ng-app="myapp">
<div ng-controller="ctrlParent">
<select class="day" id="DateOfBirth_Day" name="DateOfBirthDay" required ng-model="dobday">
<option ng-repeat="i in getNumber(days) track by $index" value="{{$index+1}}">{{$index+1}}</option>
</select>
</div>
</div>
控制器代碼
var app = angular.module('myapp',[]);
app.controller('ctrlParent',function($scope){
$scope.days= 31;
$scope.getNumber = function(num) {
return new Array(num);
}
});
嗨,感謝您的解決方案的另一種方式。所以th鍵是
您可以使用ng-options – Achyut
爲相同的功能提供更好的代碼段嗎?好的,讓我創建一個。 –