Say I have an enum which is just
export enum TestEnum {
A = 'A',
B = 'B',
C = 'C',
}
and in my components.ts method you can find this:
optionsTestEnum: SelectItem[];
initDropdownOptionsEnum() {
this.optionsTestEnum = Object.keys(TestEnum).map(v => {
return { label: v, value: v };
});
}
SelectedItem takes the enum values from a java backend.
TestEnum.java:
public enum TestEnum {
A, B, C
}
and my component.html is something like this:
<div class="col-6 col-sm-6">
<si-newton-form-group [label]="'testFlag' | translate" ccFormGroup>
<p-dropdown [options]="optionsTestEnum" formControlName="testFlag"
[ccDisabled]="readOnly" ccNewton>
</p-dropdown>
<cc-input-validationmessage [form]="testForm" controlName="testFlag">
</cc-input-validationmessage>
</si-newton-form-group>
</div>
I would like to do an if, else statement where I can choose the values from the testenum (A,B,C) and rename these variables individually using
this.translate.instant(''),
If I write something like this:
this.optionsTestEnum = Object.keys(TestEnum).map(v => {
return { label: this.translate.instant('testEnum.test1'),, value: v };
});
}
the dropdown menu in my front-end only shows me that all three values from the enum (A,B,C) have now the same name.
The translation:
this.translate.instant(''),
uses an json file in my case en.json.
"testEnum": {
"test1": "Test 1",
"test2": "Test 2",
"test3": "Test 3",
The values from my enum instead should have the names from the json file. A should be renamed to Test 1, B should be renamed to Test 2 and C should be renamed Test 3. So how can I write an if condition in component.ts that renamed my variables correctly?
Could anybody help me?