Skip to content

Instantly share code, notes, and snippets.

@mohsinrasool
Created July 9, 2015 12:38
Show Gist options
  • Select an option

  • Save mohsinrasool/1f69f5b5fdf50b051b2a to your computer and use it in GitHub Desktop.

Select an option

Save mohsinrasool/1f69f5b5fdf50b051b2a to your computer and use it in GitHub Desktop.

Revisions

  1. mohsinrasool created this gist Jul 9, 2015.
    22 changes: 22 additions & 0 deletions year-directive.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    /**
    * 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();
    }]
    }
    });