如何解决我需要在没有依赖注入的情况下在我的 angular porgramm 中使用 ngrx-translate
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();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。