如何解决角全日历在单击日期时添加事件
您好,希望您能对此有所帮助
我正在使用Angular 10和完整日历v5,我想知道如何在单击时将事件添加到当天
export class CalendarComponent implements OnInit{
nomaction;
constructor(public dialog: MatDialog) { }
ngOnInit(): void {
}
calendarOptions: CalendarOptions = {
initialView: 'dayGridMonth',weekends: true,dateClick: this.handleDateClick.bind(this),// bind is important!
events: [
{ title: 'event 1',date: '2020-08-20' },{ title: 'event 2',date: '2020-08-21' }
]
};
handleDateClick(arg) {
const dialogRef = this.dialog.open(AddeventComponent,{
width: '250px',data: {nomaction: this.nomaction}
});
dialogRef.afterClosed().subscribe(result => {
this.nomaction = result.nomaction;
this.calendarOptions.events = [{ title: this.nomaction,date: arg.dateStr }];//a code for adding an event into the day
console.log('action',this.nomaction);
});
}
toggleWeekends() {
this.calendarOptions.weekends = !this.calendarOptions.weekends
}
}
this.calendarOptions.events不是数组,因此我无法使用push添加对象!
如何添加它而不丢失我的第一个数据!
解决方法
在您的日历选项中添加:
calendarOptions: CalendarOptions = {
initialView: 'dayGridMonth',weekends: true,dateClick: this.handleDateClick.bind(this),// bind is important!
events: [
{ title: 'event 1',date: '2020-08-20' },{ title: 'event 2',date: '2020-08-21' }
],dateClick:function (info) {
console.log("See day infos: ",info);
}
};
我让你documentation 在这里
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。