Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
162
rated 0 times [  164] [ 2]  / answers: 1 / hits: 27921  / 8 Years ago, wed, november 23, 2016, 12:00:00

I want to create a year selection dropdown. year must start from this year upto next 7 years .



I have tried



var year = new Date().getFullYear();
var range = [];

range.push(year);

for (var i = 1; i < 7; i++) {
range.push(year + i);
}

$scope.years = range;

<select class=form-control ng-options=year for year in years name=expiryMonth ng-model=expiryMonth required>'


But this creates a html ,



<option label=2016 value=number:2016>2016</option>


this creates a required year dropdown
But i want Value to be last two digits of label



Also, my first option should be like



<option value=>select month</option>

More From » angularjs

 Answers
17



angular.module('app', [])
.controller(Ctrl,
function contactListCtrl($scope) {

var year = new Date().getFullYear();
var range = [];
range.push(year);
for (var i = 1; i < 7; i++) {
range.push(year + i);
}
$scope.years = range;


});

<!DOCTYPE html>
<html ng-app=app>

<head>
<link [email protected] data-semver=3.3.6 rel=stylesheet href=https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.css />
<script [email protected] data-semver=1.4.9 src=https://code.angularjs.org/1.4.12/angular.js></script>

<script src=script.js></script>
</head>

<body ng-controller=Ctrl>

<select class=form-control ng-model=expiryMonth required>
<option>Select month</option>
<option ng-repeat=year in years>{{year}}</option>
</select>
</body>

</html>




[#59948] Monday, November 21, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
myakylas

Total Points: 66
Total Questions: 85
Total Answers: 95

Location: Guadeloupe
Member since Sat, Aug 22, 2020
4 Years ago
myakylas questions
Thu, Apr 28, 22, 00:00, 2 Years ago
Thu, Apr 8, 21, 00:00, 3 Years ago
Sat, Sep 19, 20, 00:00, 4 Years ago
;