У меня есть таблица с gridOptions
, я могу хорошо перевести данные, но если я попытаюсь перевести в функцию phaseSwitcher
, я получу осложнения.
constructor(private http: HttpClient, private translate: TranslateService) {
this.gridOptions = <GridOptions>{};
this.gridOptions = <GridOptions>{};
this.translate.get(['projectList']).subscribe(res => {
this.columnDefs = [
headerName: res['projectList'][0]['client'],
field: 'client',
headerTooltip: res['projectList'][0]['client.tooltip'],
width: 130
},
{
headerName: res['projectList'][0]['fase'],
field: 'phase',
headerTooltip: res['projectList'][0]['fase.tooltip'],
valueFormatter: this.phaseSwitcher,
width: 110
}
]}
];
});
}
У меня правильные значения в моих client
, client.tooltip
, ... и т. Д. В моих headerName
.
Затем приходит мой проблемный метод:
phaseSwitcher(params) {
let phase;
TranslateService.prototype.get(['text']).subscribe(val => {
console.log('valoo ', val['text']);
switch (params.value) {
case 0:
phase = 'Fase 0';
break;
case 1:
phase = 'Fase 1';
break;
default:
phase = 'Fase X';
break;
}
});
return phase;
}
Я получаю эту ошибку:
ERROR TypeError: Cannot read property 'translations' of undefined
at Object.get [as translations] (core.es5.js:3076)
at Object.webpackJsonp../node_modules/@ngx-translate/core/@ngx-translate/core.es5.js.TranslateService.get (core.es5.js:3314)
at webpackJsonp../src/app/project-list/project-list.component.ts.ProjectListComponent.phaseSwitcher (project-list.component.ts:129)
at ExpressionService.webpackJsonp../node_modules/ag-grid/dist/lib/valueService/expressionService.js.ExpressionService.evaluate (expressionService.js:35)
at ValueFormatterService.webpackJsonp../node_modules/ag-grid/dist/lib/rendering/valueFormatterService.js.ValueFormatterService.formatValue (valueFormatterService.js:52)
at CellComp.webpackJsonp../node_modules/ag-grid/dist/lib/rendering/cellComp.js.CellComp.getValueAndFormat (cellComp.js:669)
at new CellComp (cellComp.js:55)
at rowComp.js:927
at Array.forEach (<anonymous>)
at RowComp.webpackJsonp../node_modules/ag-grid/dist/lib/rendering/rowComp.js.RowComp.createCells (rowComp.js:926)