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
return this.service.doSomething(params.value);it means that you usethisas a reference to the ag-grid component, it is not a reference to your hosted component. Therefore, you need to encapculate logic with a new private function inside your component and there you should usethisto reference your hosted component and its injected service. - hastrb