点击下一个和上一个按钮日期应该如下所示改变:
答案 0 :(得分:0)
对于这样的功能,我使用带有下一个代码的moment.js:
模板:
<div class="month">
<i class="fa fa-angle-left fa-2x" aria-hidden="true" (click)="prevMonth()"></i>
<span>{{month}}</span>
<i class="fa fa-angle-right fa-2x" aria-hidden="true" (click)="nextMonth()"></i>
</div>
Component.ts:
date: Date = new Date();
month = moment().format('MMMM');
dateNow = moment();
prevMonth() {
this.month = moment(this.dateNow).subtract(1, 'months').format('MMMM');
this.dateNow.subtract(1, 'months');
}
nextMonth() {
this.month = moment(this.dateNow).add(1, 'months').format('MMMM');
this.dateNow.add(1, 'months');
}