angular - 错误类型错误:labels.slice 不是使用@ngx-translate Angular 的函数 barChartLabels 图
问题描述
我想在使用 @ngx-translate Angular 时翻译 barChartLabels。
我有这段代码显示错误。
在 en.json 我添加这部分代码:
{ .....
"waiting-approval": "Waiting Approval",
"barChartLabels": {
"initiated": "Initiated",
"in-progress": "In Progress",
"completed": "Completed",
"not-possible": "Not Possible"
}
}
}
在 .ts 组件中,我有以下代码:
(response: any) => {
console.log('responese compaints', response)
this.barChartLabels = response.bar_labels;
this.barChartData = response.data;
}
并得到
["initiated", "in-progress", "completed", "not-possible"]
在 .html 代码中
我有
<canvas baseChart [datasets]="barChartData" [labels]="'barChartLabels' | translate"
[options]="barChartOptions" [plugins]="barChartPlugins" [legend]="barChartLegend"
[chartType]="barChartType">
</canvas>
你能问我如何翻译吗?
解决方案
进口
import {TranslateService} from '@ngx-translate/core';
注入服务
constructor(private translateService: TranslateService){}
和
this.translateService.instant('something.else')
推荐阅读
- mysql - 当我没有匹配的列时如何从其他表中获取特定 id 的结果
- javascript - 使用@public JsDoc 标记和@export 会导致警告
- sql - 选择替换其他列值的值
- excel - 遍历列表并为每个项目运行代码(VBA)
- wordpress - 使用 ACF 创建新的自定义帖子类型时更新帖子标题
- qlikview - Qlikview 滚动 52 周报告
- php - 在 POST 期间无限制地发送大量变量
- javascript - 选择页面上具有相同外观的项目扩展脚本
- javascript - 在网络表单上实施自动完成建议
- maven - 具有多个 wsdl 文件的相对 wsdlLocation