EnzoDLP
November 13, 2017, 10:27am
1
Hi, I am currently using ngx translate which works very well in html with “{{‘try’ | translate}}” and the file en.json “” try “:” test “” however I can not to use in the TS, for an alert!
On the doc (https://ionicframework.com/docs/developer-resources/ng2-translate/ ) I tried those he says all down on that but I can not … could you help me?
Thanks you
constructor(translate: TranslateService) {
}
showTest() {
let myTitle: string = this.translate.instant('try'); // try = your key
let confirm: this.alertCtrl.create({
title: myTitle,
...
1 Like
EnzoDLP
November 13, 2017, 11:02am
3
Thanks for your help ! “Property ‘translate’ does not exist on type ‘TryPage’”
That works for me:
Page.ts
import { TranslateService } from ‘@ngx-translate /core’;
…
test= ‘’;
constructor(private translate: TranslateService) {
this.translate.get(‘test’).subscribe((result) => {
this.test = result;
});
}
Page.module
import { TranslateModule } from ‘@ngx-translate /core’;
…
imports: [
…
TranslateModule
1 Like
Did you declare it in your constructor? Don’t forget the import too
import { TranslateService } from '@ngx-translate/core';
constructor(translate: TranslateService) {
}
1 Like
EnzoDLP
November 13, 2017, 12:08pm
6
Yeah i did but still this error …
EnzoDLP
November 13, 2017, 12:09pm
7
I get the error … but the alert is not in the constructor
Maybe a keyword like private
is missing?
Full answer:
import { TranslateService } from '@ngx-translate/core';
constructor(private translate: TranslateService) {
}
showTest() {
let myTitle: string = this.translate.instant('try'); // try = your key
let confirm: this.alertCtrl.create({
title: myTitle,
...
1 Like
EnzoDLP
November 13, 2017, 12:17pm
9
Yeeees! it works ! thank you very much it’s nice!
1 Like