简体   繁体   中英

ng2-translate on component file combined with charts.js

I am using ng2-translate on my ionic2 app, and it's working nicely on static text on html files:

<button ion-item *ngFor="let examTaken of examTakenList" (click)="selectExamTaken(examTaken)">
  {{'menu.'+examTaken.name | translate }} - {{examTaken.createdAt | date: "dd.MM.yyyy"}}
</button>

But I don't know how to translate strings on component files combined with charts.js like:

     @Input() examTakenList: Promise<Array<ExamTaken>>;
  lineChartData: Array<any> = [
    { data: [], label: 'Richtige Antworten in %' }
  ];
  lineChartLabels = new Array<string>();
  lineChartOptions: any = {
    animation: false,
    responsive: true
  };

I want to translate the label: 'Richtige Antworten in %'.

How can I use ng2-translate pipe in typescript and JavaScript files ?

Thanks in Advance

I dont know in jaavascript, but in typescript you should import :

import {TranslateService} from "ng2-translate";

Load it into your constructor :

constructor(private translate : TranslateService) { }

and use it into your code like this:

this.translate.instant("global.congratulation")

This one is working to me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM