Skip to content

Instantly share code, notes, and snippets.

@marcelloinfoweb
Forked from mohsinrasool/year-directive.js
Created April 22, 2020 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcelloinfoweb/f2e17bb0b8d8c5b14c8fcd7ca8144321 to your computer and use it in GitHub Desktop.
Save marcelloinfoweb/f2e17bb0b8d8c5b14c8fcd7ca8144321 to your computer and use it in GitHub Desktop.
An AngularJS directive to create a dropdown of years
/**
* Usage: <year-select offset=0 range=10 />
*
*/
app.directive('yearSelect',function(){
var currentYear = new Date().getFullYear();
return {
restrict: 'AE',
replace: true,
scope:{ },
template: '<select ng-options="y for y in years"></select>',
controller: ["$scope", "$element", "$attrs", function (scope, element, attrs) {
scope.years = [];
for (var i = (attrs.offset*1); i < (attrs.range*1) + 1; i++){
scope.years.push(currentYear + i);
}
// $scope.selected = moment().year();
}]
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment