The smeEnumConverter pipe operates in two ways.
Custom enum mapping allows you to provide a custom set of values to map an enum. In this mode the pipe argument is a map of numbers to other value.
In the example below, we are mapping the selected value of our color property to a css color.
This is the selected color.
Extended enums are typescript enums that have a module with a similar name appended with 'Enum' (see code below). This allows us to define common functions in that module that help work with the enum.
When this pipe is used in extended enum mode, the first argument is the id of the enum. The second optional argument is the type of translation to do. This option can be "localized" (default) or "raw".
It is assumed that EnumConverterPipe.registerEnum([enum]) has been called somewhere in the application, where [enum] is an extended enum with the enum id.
The extended enum pattern allows for a greater shared implementation of enum related logic. Here is how we implemented this pattern for this example.
{{code.colorTs}}
{{code.componentTs}}
{{code.componentHtml}}