Q:

Angular TypeScript using enum with Spring Boot Backend

I have a question for a best practice. I want to use an enum for gender in a registration form in Angular. In my backend I use Spring Boot in Java and created the enum Gender.
What is now the way to show up the Gender values in the registration form? Should I implement the enum in TypeScript or how can I call it from Spring and is this efficient?

A:

Create the enum with string values, like this:
export enum Gender {
    MALE = 'MALE',
    FEMALE = 'FEMALE'
}

And in your component TS create a field to validate the enum in your template:
gender = Gender;

So, in your html template:
<div *ngIf="customer.gender === gender.MALE"></div>

Remember, Typescript Enums are default Numeric.

