How to get translate value from ng2-translate


#1

I would like to get translate value in js, but failed.
Anybody able to advise how can I get ng2-translate value.

Below is my code
en.json
"title" : "Test Title",

app.js

this.translate.get(“title”).subscribe(this.translatedValue);
console.log("translates : " + this.translatedValue);

Console log
log translates : undefined


#2

you can have a look to this post here


#3

I tried

console.log("translates : " + this.translate.get(‘title’).value);

and

console.log("translates : " + this.translate.instant(‘title’));

both also return me the same value “title”, but it should be “Test Title”

log translates : title

but if I put my code is after initiate translate service, the result is

log translates: undefined


#4

I think you will need to show us a bit more code (init, import, etc)

which version are you using?


#5

hi
can you solve the problem?


#6

Yes. I solved.

Sample code:

this.translate.get(“title”).subscribe(res => {
console.log(“title:” + title);
});