I'm trying to set the color of all 'button' and 'a' tags to a color coming from a variable. Like this, which obviously doesn't work.
@Component({
styles: [`
a, button {
color: {{ color_from_variable }};
}
`]
This worked for me :
export const mainColor = 'blue';
@Component({
...
styles: [`
p {
color: `+mainColor+`;
}
`]
})
Here is a StackBlitz example I made for this : https://stackblitz.com/edit/angular-vpaarz
You can use ngStyle:
<some-element [ngStyle]="{'font-style': styleExp}">...</some-element>
<some-element [ngStyle]="{'max-width.px': widthExp}">...</some-element>
<some-element [ngStyle]="objExp">...</some-element>
[class.some-class]="..."or[ngClass]="..."on the element or@HostBinding('class.some-class') someClass= true;'ngStyleas posted in the answer below.