angular.module('app', [])
.controller('CalendarioCtrl', function() {
var vm = this;
vm.meses = [{
nombre: 'Enero',
numero: 1
}, {
nombre: 'Febrero',
numero: 2
}, {
nombre: 'Marzo',
numero: 1
}, {
nombre: 'Abril',
numero: 4
}, {
nombre: 'Mayo',
numero: 5
}, {
nombre: 'Junio',
numero: 6
}, {
nombre: 'Julio',
numero: 7
}, {
nombre: 'Agosto',
numero: 8
}, {
nombre: 'Septiembre',
numero: 9
}, {
nombre: 'Octubre',
numero: 10
}, {
nombre: 'Noviembre',
numero: 11
}, {
nombre: 'Diciembre',
numero: 12
}];
vm.semana = ['Domingo', 'Lunes', 'Martes', 'Miercoles', 'Jueves', 'Viernes', 'Sabado'];
})
.filter('calendario', function() {
return function(input) {
if (input) {
var result = [];
var year = moment().year();
var startDay = moment(input + '/01/' + year);
var endDay = startDay.clone().endOf('month');
var prefix = startDay.weekday();
var dayPrevMonth = startDay.clone().day(0).date();
var endPrevMonth = startDay.clone().day(0).endOf('month').date();
if (endPrevMonth - dayPrevMonth < 7) {
for (var i = dayPrevMonth; i <= endPrevMonth; i++) {
result.push({
day: i,
current: false
});
}
}
var days = startDay.daysInMonth();
for (var i = 0; i < days; i++) {
result.push({
day: i + 1,
current: true
});
}
var endNextWeek = endDay.clone().day(7).date();
for (var i = 1; i < endNextWeek; i++) {
result.push({
day: i,
current: false
});
}
return result;
}
};
});
ul {
list-style: none;
margin: 0;
padding: 0;
}
.header {
font-weight: bolder;
font-size: 12px;
}
.calendar.header .day {
height: 30px;
}
.calendar {
position: relative;
width: 100%
}
.calendar .day {
float: left;
width: 13.8%;
height: 100px;
border: solid 1px lightgray;
}
.calendar .day.other {
background-color: lightgray;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="http://momentjs.com/downloads/moment.min.js"></script>
<div ng-app="app" ng-controller="CalendarioCtrl as vm">
<select ng-options="mes.numero as mes.nombre for mes in vm.meses" ng-model="vm.selected">
</select>
<br>
<br>
<div ng-if="vm.selected">
<ul class="calendar header">
<li class="day" ng-repeat="dia in vm.semana">{{dia}}</li>
</ul>
<ul class="calendar">
<li class="day" ng-class="{other: !item.current}" ng-repeat="item in vm.selected | calendario track by $index">
{{item.day}}
</li>
</ul>
</div>
</div>