I am using Angular5 and trying to get the dayClick() event of the fullcalendar.io jquery plugin to callback to the angular component so I can open an angular component dialog populated from the calendar details.
To setup example do this, in console:
ng new pjt
cd pjt
npm install jquery fullcalendar --save
Update to .angular-cli.json to include
[styles]
"../node_modules/fullcalendar/dist/fullcalendar.min.css"
[scripts]
"../node_modules/jquery/dist/jquery.js",
"../node_modules/moment/min/moment.min.js",
"../node_modules/fullcalendar/dist/fullcalendar.min.js"
Add to main.ts
import * as jQuery from "jquery";
(window as any).$ = (window as any).jQuery = jQuery;
update the app.component.html
<div id='calendar'></div>
<div id="test" (click)="Clicked()" hidden="true"></div>
Add to app.component.ts
import 'fullcalendar';
declare let $:any;
@Component({...})
export class AppComponent {
...
ngOnInit(){
$('#calendar').fullCalendar({
dayClick: function(date, jsEvent, view) {
//alert('Clicked on: ' + date.format());
$(this).css('background-color', 'red');
***** WANT A BETTER WAY TO CALL NG CLICKED() FUNCTION HERE TO REPLACE THE FOLLOWING 2 LINES *****
document.getElementById("test").innerText = date.format();
document.getElementById("test").click();
}
});
$('#calendar').fullCalendar('changeView', 'agendaDay');
}
Clicked() {
alert("Alert from ng func");
}
}
Then ng server
and click the day schedule part of the calendar.
NOTE this is angular 5 so it doesn't look like ng-controller or scope from ng v1 seems to be the right way to do this. I am looking for a cleaner way to call the function without having to have the 'test' div.