Problem :
I have dynamic text that is coming from Json file. I am using translate.get() method like this:
this.translate.get('keyInJson').subscribe(res => {
this.valueFromJson = res;
/*
creating an object using above text
*/
});
As this is asynchronous I am not able to get the translated text when the page renders. I tried wrapping above method inside Observables , Promises but it's not able to get translated version of text during page load. I was able to get the translated text after trying different approaches but code became too complex and not reliable.
Expected/desired behavior Should load translated version of text
Reproduction of the problem Dynamically generate the text instead of hardcoding it on html and then try to render translated version.
Environment Angular2 , Typescript, Ionic 2
valueFromJsonis used? If the above code is in, for example, the constructor of a component, and you want to use the value in the component's template, then you should be able to put{{valueFromJson}}in the template without issue.