Angular Filter Current Months

by TheFiddler

HTML

<div ng-app="test">
  <div ng-controller="Ctrl">
    <li ng-repeat="currMonth in months">{{currMonth}}</li>
  </div>
</div>

JavaScript

angular.module('test', []).controller('Ctrl', function($scope) {
    var date = new Date();
    var months = [],
        monthNames = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
    "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ];
    for(var i = 0; i < 12; i++) {
        months.push(monthNames[date.getMonth()] + ' ' + date.getFullYear());
        
        // Subtract a month each time
        date.setMonth(date.getMonth() - 1);
    }
    $scope.months = months;
});