I'm attempting to retrieve array values from the en.json translation file in Angular and then bind them to an object property using the code snippet below.
Here is the TypeScript code:
ngOnInit() {
this.en = {
dayNamesMin: this.translateSvc
.get(['calendar.day_names_min.Sun', 'calendar.day_names_min.Mon', 'calendar.day_names_min.Tue', 'calendar.day_names_min.Wed',
'calendar.day_names_min.Thu', 'calendar.day_names_min.Fri', 'calendar.day_names_min.Sat'])
.subscribe(translated => {
console.log(Object.keys(translated).map(key => translated[key]));
return Object.keys(translated).map(key => translated[key]);
})
};
};
The en.json file has the following structure:
{
"calendar" : {
"day_names_min": {
"Sun": "SUN",
"Mon": "MON",
"Tue": "TUE",
"Wed": "WED",
"Thu": "THU",
"Fri": "FRI",
"Sat": "SAT"
}
}
}
I'm utilizing the ngx translator service to extract data from the en.json file, subscribe to it, and assign the value to the dayNamesMin property of the this.en object.
Although when I log the value Object.keys(translated).map(key => translated[key]); in the console, it correctly displays the array ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"]. Unfortunately, it doesn't seem to bind to the object's property dayNamesMin.
Any assistance would be greatly appreciated!