2017-02-26 116 views
0

我要尋找從 我已經HTML設置爲如何設置動態CSS樣式[ngStyle]

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

我的組件MS-工具欄和設置[ngStyle] 動態CSS TS我有初始化作爲

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

但是在渲染它不工作。渲染它設置元素

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

我採用了棱角分明的版本2.3.1

請提出一些更好的方式來做到這一點。

+4

[中動態更新的CSS可能的複製Angular 2](http://stackoverflow.com/questions/35882670/dynamically-updating-css-in-angular-2) – lin

+0

我想要如此設置對象,它具有來自ts文件的css屬性,正如我所描述的那樣引用[ngStyle ] – hitVPS

回答

1

什麼你做是正確的只是檢查你的目標代碼

您需要的顏色代碼添加

下面的代碼使用

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