我目前正在建立一个日程安排应用,这个应用有前一天、当前一天和第二天的按钮。我如何创建一个当日按钮?
HTML文件
<button type="button" (click)="previousDay()" >Left</button>
<br>
<h2>{{ currentDay }}</h2>
<br>
<button type="button" (click)="nextDay()" >Right</button>
<br>
<button type="button" (click)="currentDay()" >Current Day</button>
<br>
</div>
TypeScript文件。
export class DayViewComponent implements OnInit {
events: any[];
currentDay: Date;
modalActive: boolean = false;
previousDay() {
this.currentDay.setDate(this.currentDay.getDate()-1);
}
nextDay() {
this.currentDay.setDate(this.currentDay.getDate()+1);
}
currentDay(){
}
}
我对你的函数的命名很谨慎。命名为 currentDay
约会 和 一个函数。在你的函数前加上'set'怎么样?
setCurrentDay() {
this.currentDay = new Date()
}