Skip to content

Instantly share code, notes, and snippets.

@mohsinrasool
Created July 9, 2015 12:40
Show Gist options
  • Save mohsinrasool/53ad55db31a47898b4df to your computer and use it in GitHub Desktop.
Save mohsinrasool/53ad55db31a47898b4df to your computer and use it in GitHub Desktop.
An AngularJS directive to generate dropdown of months
/**
* Usage <year-select range=10 offset=0 />
*
*
*/
app.directive('monthSelect',function(){
return {
restrict: 'E',
replace: true,
scope:{ },
template: '<select><option ng-repeat="month in months" value="{{month.value}}" ng-selected="month.value == selected">{{month.text}}</option></select>',
// template: '<select ng-options="month.value for month in months"></select>',
controller: ["$scope", "$element", "$attrs", function (scope, element, attrs) {
scope.months = [];
scope.months.push({value:1, text:'January'});
scope.months.push({value:2, text:'February'});
scope.months.push({value:3, text:'March'});
scope.months.push({value:4, text:'April'});
scope.months.push({value:5, text:'May'});
scope.months.push({value:6, text:'June'});
scope.months.push({value:7, text:'July'});
scope.months.push({value:8, text:'August'});
scope.months.push({value:9, text:'September'});
scope.months.push({value:10, text:'October'});
scope.months.push({value:11, text:'November'});
scope.months.push({value:12, text:'December'});
// var currentMonth = new Date().getMonth();
scope.selected = moment().month() +1;
}]
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment