In the current project, I am facing a situation where I need to work around and initialize jQuery datetimepicker inside an Angular 2 application (with plans to refactor it later).
However, when I assign a datetime value to a variable, I encounter a problem where it is not visible elsewhere in the Angular app. Here is my current approach:
datetime: string;
setDT() {
jQuery(this.elementRef.nativeElement).find("#datetimepicker").datetimepicker({
onChangeDateTime: function(currentDateTime) {
this.datetime = currentDateTime;
console.log(this.datetime); // -> logs correct selected datetime, i.e. Fri Mar 11 2016 10:00:00 GMT+0200 (EET)
}
});
}
Unfortunately, when I try to access this.datetime from another part of the code, it returns 'undefined':
save() {
console.log(this.datetime); // -> 'undefined'
}
I am seeking guidance on how to effectively pass variables between jQuery and Angular 2.
Regards, Roman