For my Angular 2 application, I am using the Bootstrap datepicker plugin () but encountering some initialization issues.
The code snippet below is currently working for initializing the datepicker in my component, however, it does not look very clean:
ngAfterViewInit(): void {
setTimeout(function() {
$('.date').each(function() {
console.log($(this));
$(this).datepicker({
format: 'dd.mm.yyyy',
autoclose: true,
calendarWeeks: true,
language: 'de-DE',
todayHighlight: true
});
});
}, 1000)
}
Is there a cleaner way to make this work without relying on a 1-second timeout? Without the timeout, the jQuery selector does not return anything and no output is shown in the console.