问题描述
export const assetDepreciationProgressColumn: ExtendedAssetColumn = new AssetColumnBuilder()
.specifyAssetType(AssetType.Depreciation)
.setColumn({
...intColumn<DepreciatingAsset>(
{ id: 'dp',displayHeader: 'depreciation progress' },(x): number => getDepreciationProgress(x,'minute') * hundred
),tooltip: (
a: DepreciatingAsset
): string => //translated tooltip>
`${(getDepreciationProgress(a,'minute') * 100).toFixed(2)}% actually depreciated,` +
`${((a.bookings.filter(x => Boolean(x.doneAt)).length / a.bookings.length) * hundred || 0).toFixed(2)}% booked`,bookedProgress: (a: DepreciatingAsset) =>
(a.bookings.filter(x => Boolean(x.doneAt)).length / a.bookings.length) * hundred,})
.build();
这是我表中的一列,我需要在没有 DI 的情况下使用 ngrx-translate 翻译“实际折旧”和“预订”
解决方法
我从我的常量中创建了一个可注入的服务,然后我可以在我的类中的构造函数中注入翻译服务
@Injectable({ providedIn: 'root' })
export class AssetsColumns {
constructor(private readonly translateService: TranslateService) {}
assetDepreciationProgressColumn: ExtendedAssetColumn = new AssetColumnBuilder()
.specifyAssetType(AssetType.Depreciation)
.setColumn({
...intColumn<DepreciatingAsset>(
{ id: 'dp',displayHeader: 'depreciation progress' },(x): number => getDepreciationProgress(x,'minute') * hundred
),// actually idk why there was condition that makes progress bars full with '-' value),tooltip: (a: DepreciatingAsset): string =>
`${(getDepreciationProgress(a,'minute') * 100).toFixed(2)}% ${this.translateService.instant(
'assets.progress.actuallydepreciated'
)},` +
`${((a.bookings.filter(x => Boolean(x.doneAt)).length / a.bookings.length) * hundred || 0).toFixed(
2
)}% ${this.translateService.instant('assets.progress.booked')}`,bookedProgress: (a: DepreciatingAsset) =>
(a.bookings.filter(x => Boolean(x.doneAt)).length / a.bookings.length) * hundred
})
.build();