In my current project, I am looking to add a feature that allows users to choose the color scheme of the software. While the choices are currently limited, I plan to implement a color picker in the future to expand the options available.
So far, I have experimented with using [style.background-color]
, which works well for certain attributes but does not apply to elements created through selectors like :after
, :before
, and :hover
. This is where [attr.data-background-color]
comes in; by utilizing this attribute and applying it in the CSS file, I can style these elements accordingly.
[data-background-color].element:after{
...
content: attr(data-background-color);
background-color: attr(data-background-color);
...
}
I also attempted to use variables and incorporate them via
[ngStyle]="{'--bg: backgroundColor'}"
but encountered some difficulties in Angular. Despite this, I recognize that these methods align closely with what I aim to achieve.
Ultimately, I am seeking an alternative approach to avoid defining multiple classes and relying on [ngClass]
solely for setting colors.