hitVPS
hitVPS

Reputation: 3

how to set dynamic css style for [ngStyle]

I am looking for setting dynamic css for [ngStyle] from my component ms-toolbar I have set html as

<md-toolbar class="ms-toolbar" [ngStyle]="StylingToolbar">
</md-toolbar>

and from ts I have initialize as

    export class AppbarComponent {
     StylingToolbar = {
    'background-color': '00bcd4',
    'color':'white'
  };
}

But on rendering it is not working. On rendering It is setting element as

<md-toolbar _ngcontent-alm-42="" class="ms-toolbar" ng-reflect-ng-style="[object Object]">

I am using Angular version 2.3.1

Please suggest some better way to do this.

Upvotes: 0

Views: 1085

Answers (1)

Mrunal Shidurkar
Mrunal Shidurkar

Reputation: 317

What you have did is right just check your object code

You need to add # before color code

Use below code

export class AppbarComponent {
     StylingToolbar = {
    'background-color': '#00bcd4',
    'color':'white'
  };
}

Upvotes: 1

Related Questions