I am facing a challenge where I have a class name stored in a variable and I need to apply it to the host element of my Angular2 component. However, I am struggling to find a solution for this.
While I can easily add a constant string as a class using HostBinding, the issue arises when trying to use variables since they are not available during the initialization process of HostBinding. This results in the class being set to "undefined" when attempted.
Is there a way to dynamically add a class from a variable to the host element? Perhaps initializing HostBinding in the constructor after the variables are accessible could work. Using ngClass would be ideal, but unfortunately, it cannot be applied directly to the host element.
On a related note - I am utilizing CSS theming with host-context(.my-theme), which is why I need to apply this main class to the Angular2 component. If there is an alternative method to achieve this without relying on variables, I am open to innovative suggestions. The theme name is dynamic, making it non-constant.