Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call service from ag-grid valueFormatter

Does anyone know how to call service from ValueFormatter of ag-grid in Angular2+?

Example:

I have injected a service called someService in the constructor and would like to call the service from the ValueFormatter. What should i do to achieve that?

constructor(private service: SomeService) { }

this.columnDefs.push(
        {
            headerName: 'Date',
            width: 150,
            field: 'incidentDate',
            valueFormatter(params) {
                return this.service.doSomething(params.value);
            }
        });

At the moment, it doesn't recognise the service from the valueFormatter.

Thanks in advance

like image 618
developer Avatar asked Dec 10 '22 07:12

developer


1 Answers

I have found a solution to my problem. I simply need to do the following:

 this.columnDefs.push(
    {
        headerName: 'Date',
        width: 150,
        field: 'incidentDate',
        valueFormatter: this.anotherFunction.bind(this)
    });

anotherFunction(params): string {
    return this.service.doSomething(params.value);
}
like image 150
developer Avatar answered Dec 28 '22 07:12

developer