I've been working on creating a dropdown for Date of Birth using ng-options. I've managed to set it up for day and month, but I'm encountering an issue with the year dropdown. The problem is that the years are displayed in reverse order, starting from 2014 to 1915, but the values are from 1 to 100 instead of 2014 to 1915. Can you suggest a better approach? I feel like the current method is a bit outdated. I prefer not to use ng-repeat.
HTML
<select class="day" id="DateOfBirth_Day" name="DateOfBirthDay" required ng-pattern="\d+" ng-model="user.question5.answer.dobday" ng-options="o for o in days">
<option value="DD">DD</option>
</select>
<select class="month" id="DateOfBirth_Month" name="DateOfBirthMonth" required ng-pattern="\d+" ng-model="user.question5.answer.dobmonth" ng-options="o for o in months">
<option value="MM">MM</option>
</select>
<select class="year" id="DateOfBirth_Year" name="DateOfBirthYear" required ng-pattern="\d+" ng-model="user.question5.answer.dobyear" ng-options="o for o in years">
<option value="YYYY">YYYY</option>
</select>
Controller Code
$scope.user = {
question5: {
answer: {
dobday: 'DD',
dobmonth: 'MM',
dobyear: 'YYYY'
}
}
}
$scope.totaldays = 31;
$scope.totalmonths = 12;
$scope.totalyears = 100;
$scope.days = ['DD'];
for (var i = 0; i < $scope.totaldays; i += 1) {
$scope.days.push(i + 1);
}
$scope.months = ['MM'];
for (var i = 0; i < $scope.totalmonths; i += 1) {
$scope.months.push(i + 1);
}
$scope.years = ['YYYY'];
for (var i = 2014; i > 2014 - $scope.totalyears; i--) {
$scope.years.push(i - 1);
}