Angular: How do I change value based on key value

C0mpl3x

Hello so I'm getting a string value and I want to pass it to another function. So for example if I get 'eng' I want it to be 'en'. I don't want to use slice or if. I tried making an enum but that didn't work.

ngOnInit(): void {    
this.setLocaleDateFormat(this.translateService.currentLang);
    }

 setLocaleDateFormat(language: Languages): void {
    this.dateAdapter.setLocale(language);   } 

export enum Languages {   
'eng' = 'en',   
'slk' = 'sk',   
'cze' = 'cz',
 }

So I want to pass the value and based on some template change it to something else. I'm getting eng but I want to setLocale to en for expample.

makinyelure

From you post, I believe this.translateService.currentLang will return 'eng'. I doubt this but going back to your question. Languages should not be an enum. It should be a constant object.

export const Languages = {
  eng: 'en',
  slk: 'sk',
  cze:  'cz',
};

setLocaleDateFormat(): void {
    this.dateAdapter.setLocale(Languages[this.translateService.currentLang]);
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do i filter a value of key in an object based on matching value?

How do I change a key's value to that of another key's value if the value is the name of another key?

Angular change ngClass based on key value

How do I select an Object based on the key value - VueJS

How do i sort nested dictionary based on value of first key

How do I change element value based on the data attribute?

How do I change value in a pandas series based on condition

How do I change the color of an infobox in shinydashboard based on a string, not a value?

How do I change the value of a cell based on the position of a team in a table?

Using JPath, how do I return a value based on another key value pair of the same node?

In C#, how do I change a Key-Value-Property's value while recursively traversing an ExpandoObject?

How do I conditionally change the value of a variable based on the value of another variable?

How do I change value of an array to another value based on a different array?

How do I change a value within a variable based on the value of another variable in R?

How can I return the value of a key based on a different value in a dictionary

How do you change a Multidimensional Array Key to a Childs Key Value?

How can I set a value to an key value pair property in Angular?

How to change key value based on comparison of array of objects in jQuery?

How do I change the value of a textbox with this JQuery?

How do I change a value in a .npz file?

How Do I Change The Appended Input Value?

How do I change the value of an appended string?

How do I change the MTU value on Ubuntu?

How do I change the value of an item in a Set?

How do I change this value using regex?

How do I change a value of a variable in this case?

How do I change the format of a value in a table?

How do I change the value in an array? Mongoose

How do I change the value and save it to a file?