How do I pass angular services into Tabulator JS?
I am attempting to set a rowClick() function on a Tabulator table.
The rowClick() will pass the row Data into a service.
import { Component, AfterViewInit } from '@angular/core';
import { FuzeUser } from 'src/app/models/fuze-user';
import { UserEditService } from 'src/app/services/user-edit.service';
import { UserService } from 'src/app/services/user.service';
import Tabulator from 'tabulator-tables';
@Component({
selector: 'app-user-table',
templateUrl: './user-table.component.html',
styleUrls: ['./user-table.component.scss']
})
export class UserTableComponent implements AfterViewInit {
tab = document.createElement('div');
public tableName: string = 'fuze-user-table';
private columns: any[] = [];
private rows: any[] = [];
table: Tabulator;
public drawn: boolean = false;
constructor(private userService: UserService, private userEditService: UserEditService) {
}
private drawTable(): void {
this.table = new Tabulator(this.tab, {
layout: "fitDataStretch",
movableColumns: true,
maxHeight:"485px",
pagination: "local",
paginationSize: 25,
paginationSizeSelector: [25, 50, 100],
selectable: true,
selectableRangeMode: "click",
data: this.rows,
columns: this.columns,
rowClick:function(e, id, data, row){
this.userEditService.setUser(data);
}
});
document.getElementById(`${this.tableName}`).appendChild(this.tab);
}
}
I have also attempted to create a function, that calls this.userEditService.setUser, within my component class, and then passed that method to tabulator. This also failed because the method passed cannot find anything within the scope of the service.
I think that the service cannot be found because the scope of "this" within the rowClick() function only exists within the Tabulator object. How do I go about getting access to my service from within the tabulator object?
Source: Angular Questions