Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call dynamic styles in angular2

Tags:

angular

I hereby tried to call the themeColor variable in .activeLink class, but it's not working. Is it any way to get the value dynamically? please help.

 styles:[`
    .activeLink{
        background:${this.themeColor} !important;
        color: #fff !important;
    }
`]


export class NavBarComponent implements OnInit{
  themeColor = "#ff0"
}

HTML

<a [routerLink]="['/public']" routerLinkActive="activeLink" 
[routerLinkActiveOptions]="{exact:true}"><i class="fa fa-home"></i> {{ 
'home.menu.home' | translate }}</a>
like image 822
Sridhar Avatar asked Feb 12 '26 12:02

Sridhar


1 Answers

There is no interpolation support for styles in Angular

You can use

<some-element [style.background-color]="themeColor"
like image 139
Günter Zöchbauer Avatar answered Feb 16 '26 21:02

Günter Zöchbauer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!