Pretty novice in coding, so I have no clue which language it is. I have a component.ts file which contains a function. In ngOnInit(), I have written a part of code in Js cause of dependency. Im trying to access the function written outside ngOnInit(), in this js block.
Tried accessing the function using this.openDialog(), but that just showed error saying its not defined.
Tried defining the function itself in js by creating an object of the component and trying to call the function,
constructor(public dialog: MatDialog, private datePipe: DatePipe) {
}
ngOnInit(){
var testVar = new testComponent(dia, date);
//dia, date are respective constructor params
}
Pretty sure thats not proper, but tried it.
Component.ts:
export class test implements OnInit{
openDialog(){
//this is mat angular dialog
}
ngOnInit(){
document.addEventListener('DOMContentLoaded', function () {
// trying to call the above openDialog here.
});
}
}
Trying to call the dialog inside document.addEventListener();
Converting document.addEventListener();
is not an option.
It would help if I can call that dialog inside.
Edit 1 Sharing more code, for info:
document.addEventListener('DOMContentLoaded', function () {
var events = []
var calendarEl = document.getElementById('calendar');
var calendar = new Calendar(calendarEl, {
eventLimit: true, // for all non-TimeGrid views
views: {
dayGridMonth: {
eventLimit: 5 // adjust to 6 only for timeGridWeek/timeGridDay
}
},
themeSystem: 'bootstrap',
businessHours: {
daysOfWeek: [1, 2, 3, 4, 5],
startTime: '00:00',
endTime: '24:00',
},
header: {
left: 'prev,next',
center: 'title',
right: 'dayGridMonth,listView,timeGridWeek,timeGridDay'
},
plugins: [dayGridPlugin, interactionPlugin, listPlugin, bootstrapPlugin, timeGrigPlugin],
eventOverlap: false,
displayEventTime: false,
eventClick: function (info) {
this.curEvnt = info;
console.log(this.curEvnt)
this.openDialog(info.event); //ERROR
}
});
calendar.render();
});
Open dialog is defined and can be called in onInit, but im trying to implement the above code
Error: this.openDialog is not a function