首页 > 解决方案 > 错误类型错误: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>

你能问我如何翻译吗?

更新图片 console.log('responese compaints', response)

标签: angularchartslabeltranslate

解决方案


进口

import {TranslateService} from '@ngx-translate/core';

注入服务

constructor(private translateService: TranslateService){}

this.translateService.instant('something.else')


推荐阅读