I am trying to create a decorator in Angular that allows me to mark certain properties of a component as "Options" with a specific type. The goal is to add these marked properties to a list that stores all the options. Later, I would like to call a function called getOptions()
, which should return a Map containing the option names and their corresponding property keys.
I came across this Stack Overflow answer that seems similar to my goal. However, when I tried implementing it, I encountered an error stating "Uncaught TypeError: Cannot assign to read-only property 'Symbol(fields)' of object '[object Object]'".
I would greatly appreciate any help resolving this issue and suggestions or alternative approaches to achieve my desired functionality.
Ideally, I would like to achieve the following:
@Component({...})
export class DashboardComponent {
@OptionType('ColorOption')
color: string = "";
...
ngOnInit(): void {
console.log(getAllProperties()); // Should return <<color, ColorOption>>
}
}
I've also created a Codesandbox, where you can find a working (but not correct) example and can try out your stuff! If you need any more information, feel free to ask!