I have a <span> that I want to apply dynamic style to.
Style is stored in a css-like string variable and can be arbitrary e.g.
myStyle = 'color: white; font-weight: bold;'
or
myStyle = 'background-color: red;'
I expected it to work like
<span style="{{myStyle}}">
but it didn't.
I tried different options but none seem to work for me for different reasons:
- I can't put styles in a .css file and use class names because style is coming from server in the form of aforementioned string
- Using
[style.color]etc. doesn't suit me because I don't know what the style can be - Using
[ngStyle]doesn't suit me because it expects object like{'color': 'red', 'font-weight': 'bold'}and I only have string
The reason I have a style stored in a string is because I need to apply it in HTML generated on the server where I simply pass that string to a placeholder variable in a velocity template.
I am almost confident that it can't be done the way I want but probably I am overlooking some solution.