In the html I can use ngStyle to write:
<some-element [ngStyle]="objExp">...</some-element>
Where objExp returns
return {
"background": "red"
};
This works, and turns the background of the element to red.
There are times when I want a fallback values. For example, if I was dealing with gradients I would need -webkit-linear-gradient
, -o-linear-gradient
then linear-gradient
.
I can't add multiple values with the same key to a javascript object.
I guessed at
return { "background": ["red", "blue"] }
but that doesn't seem to work. I've also tried { "background: "red, blue" }
I don't want to use the <some-element [ngStyle]="{'font-style': styleExp}">...</some-element>
because that loads complexity repetitively into my html. I can't use [style]="expresionThatGivesAString"
because it breaks in Safari.
"red" and "blue" are set at runtime, which is why I'm binding them straight to the element. So putting them in classes isn't an option.
How do I set multiple background values using ngStyle?