我有一个angular
组件,它angular-calendar
按月显示(2019 年 1 月,2019 年 2 月...)。我正在展示 6 个月,并且还有按钮可以来回navigation
移动月份。calendar
首先,我创建了一个组件并在那里实现了所有逻辑。但我需要angular-calendar
为按钮创建单独的组件和单独的组件navigation
。这是stackblitz
工作示例:- https://stackblitz.com/edit/ang-cp-7quundm
<!--code for navigation-->
<div class="display-calendar">
<button class="btn btn-sm btn-primary" (click)="getNextData()">Click next</button>
<button class="btn btn-sm btn-primary" (click)="getPreviousData()">Click previous </button>
</div>
<!--code for calendar months-->
<div class="row-items" *ngFor="let month of months">
<mat-calendar [dateClass]="dateClass()" [startAt]="month" [selected]="selectedDate"
(selectedChange)="onSelect($event)"></mat-calendar>
</div>
TS代码
ngOnInit() {
this.getMonths(this.year, this.month);
}
//show calendar in months
getMonths(year:number, month:number) {
this.months = [];
for (let i = 0; i < 6; i++) {
this.months.push(new Date(year, month++));
}
}
//navigation for next Month
getNextData() {
if(this.curMonth+1 > this.month && this.curYear+1 >= this.year){
this.month++
}
this.getMonths(this.year, this.month);
}
//Navigation for previous Months
getPreviousData(){
if(this.curMonth-12 < this.month){
this.month--
}
this.getMonths(this.year, this.month);
}
我正在考虑与服务或输入法有关。但我很困惑。
this.getMonths(this.year, this.month);
此方法需要在导航组件和日历组件中调用