The following piece of angular code displays the days in the current week:
function TodoCtrl($scope) {
var currentDate = moment();
var weekStart = currentDate.clone().startOf('week');
var weekEnd = currentDate.clone().endOf('week');
var days = [];
for (i = 0; i <= 6; i++) {
days.push(moment(weekStart).add(i, 'days').format("MMMM Do,dddd"));
};
$scope.weekDays = days;
}
And the html:
<div ng-app>
<div ng-controller="TodoCtrl">
<div ng-repeat="day in weekDays">
{{day}}
</div>
</div>
</div>
And the output is:
- January 24th, Sunday
- January 25th, Monday
- January 26th, Tuesday
- January 27th, Wednesday
- January 28th, Thursday
- January 29th, Friday
- January 30th, Saturday
what I want is a next and previous buttons. When I click the next button, the days in the next week will be shown. And when I click previous button, the days in the previous week will be shown.
Please help me.