Angular2 Calendar - dayClicked function invoked with "undefined" day parameter


#1

I am using angulart 2 calendar in my project and I have an issue with trapping the dayClicked method. Here is my code and my action script function

ionic HTML code

<mwl-calendar-month-view
[viewDate]=“today”
[headerTemplate]=“headerTemp”
(dayClicked)=“dayClicked(calendarDay)”
[dayModifier]= “dayModifier”>

action script code

dayClicked = (day) => {

alert(JSON.stringify(day));
if (this.selectedDay) {
  delete this.selectedDay.cssClass;
}
day.cssClass = 'cal-day-selected';
this.selectedDay = day;

}

When I run the browser ionic emulator , I am getting the function dayClicked invoked but the parameter is coming out as “undefined”. I am stuck and any help is appreciated

Thanks
Raees


#2

Where did you come up with this calendarDay? You can’t just choose arbitrary parameter names out of nowhere.


#3

I got it from some internet sample. Do you know what should be the parameter. Please help


#4

“Copying random stuff I found on some blog” is no way to run a railroad. I would suggest looking at the official demo code of the project instead.


#5

I am a new learner man and I saw that example and his code, it looked like this

HTML

<mwl-calendar-month-view
  [viewDate]="viewDate"
  [events]="events"
  [dayModifier]="selectDay"
   (dayClicked)="dayClicked($event.day)">

Script
dayClicked(day: CalendarMonthViewDay): void {
if (this.selectedDay) {
delete this.selectedDay.cssClass;
}
day.cssClass = ‘cal-day-selected’;
this.selectedDay = day;
}

I got error on the dayClicked($event.day) from the HTML code. ionic was not understanding the $event. If i know how to re-mediate that, might solve my problem.

Again, help is appreciated !

Raees


#6

I don’t, and nobody is going to be able to magically fix an error without an error message.