Angular services inside of gantt.attachEvent

Hello, I am currently using Angular 16 with the GANTT Chart and have services that I use through the whole application.
Currently, on ngOnInit() I have attached the event ‘onAfterTaskDrag’ and was wondering if inside such event I could call my Angular services, like so:

gantt.attachEvent("onAfterTaskDrag", function (id, mode, e) {
// ----> example <------ //
      this.AngularService
        .UpdateAngular(id, payload)
        .pipe(takeUntil(this._unsubscribeAll))
        .subscribe((result: any) => {
          console.log(result);
        });
}

The error that I get is the following: ERROR TypeError: Cannot read properties of undefined (reading ‘AngularService’) (gantt-scheduler.component.ts:150:12)|

Thanks!

At first I thought it had something to do with the gantt scope, but it ended up being just JS scope.
Updating to an arrow function should do the trick, like so:

gantt.attachEvent("onAfterTaskDrag",  (id, mode, e) =>  {
// ----> example <------ //
      this.AngularService
        .UpdateAngular(id, payload)
        .pipe(takeUntil(this._unsubscribeAll))
        .subscribe((result: any) => {
          console.log(result);
        });
}

Hope this helps :slight_smile: