有谁知道如何在 Angular2+ 中调用 ag-grid 的 ValueFormatter 服务?
示例:
我在构造函数中注入(inject)了一个名为 someService 的服务,并希望从 ValueFormatter 调用该服务。我应该怎么做才能实现这一目标?
constructor(private service: SomeService) { }
this.columnDefs.push(
{
headerName: 'Date',
width: 150,
field: 'incidentDate',
valueFormatter(params) {
return this.service.doSomething(params.value);
}
});
目前,它无法识别来自 valueFormatter 的服务。
提前致谢
最佳答案
我找到了解决问题的方法。我只需要执行以下操作:
this.columnDefs.push(
{
headerName: 'Date',
width: 150,
field: 'incidentDate',
valueFormatter: this.anotherFunction.bind(this)
});
anotherFunction(params): string {
return this.service.doSomething(params.value);
}
关于angular - 如何从 ag-grid valueFormatter 调用服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48901701/