Context: Fullcalendar v5 - Angular 13
I need to include in each event a dynamic button to perform a method (myfunction) which is placed in the typescript file.
In the calendarOptions I can work on the eventContent to add a simple html such as a button:
calendarOptions: CalendarOptions = {
...
eventContent: { html: '<button mat-button>mybutton</button>' }
}
I can also include a javascript method like an alert including it in the eventContent:
eventContent: { html: '<button mat-button onclick="alert(\'Hello\')">mybutton</button>' },
This also works, BUT I would like to trigger a method which is in my typescript model and not a native JS function.
When I try with
eventContent: { html: '<button mat-button onclick="myfunction()">mybutton</button>' },
this is not working...
and I tried obviously
eventContent: { html: '<button mat-button (click)="myfunction()">mybutton</button>' },
which is not even seeing the (click).
Apparently the angular compiler is not working here....so how can I refer to that method?
I read this Custom button for each event in ui-calendar fullcalendar BUT that is not Angular and by the way the eventRender seems to be obsolete and not present anymore in the v5 now.
This (through eventClick) is not working either:
eventClick: function (info) {
this.myfunction(info.event.id);
}
I finally tried:
views: {
timeGridWeek: { //questo modifica TUTTI gli eventi in questa vista
eventContent: function (event: any, element: any) {
let eventWrapper = document.createElement('div');
eventWrapper.addEventListener("click",function(event){ console.log(event); })
eventWrapper.innerText = 'test dayGridWeek';
var arrayOfDomNodes = [eventWrapper];
return { domNodes: arrayOfDomNodes };
}
},
},
But again, this works for a console.log, not for a custom method/function of my model.
In the end how can I launch the myfunction from a dynamically added button?