使用mat-slide-toggle更改文本样式

时间:2018-04-25 21:09:41

标签: angular angular-material2

如何使用Ang-Material-2的mat-slide-toggle更改文本样式?

enter image description here

<mat-slide-toggle [color]="primary" [checked]="true">Slide me</mat-slide-toggle>
<h3>Text</h3>

1 个答案:

答案 0 :(得分:1)

根据切换状态将类或样式属性绑定到<h3>元素:

<mat-slide-toggle #toggle [color]="primary" [checked]="true">Slide me</mat-slide-toggle>
<h3 [ngClass]="{'primary-color' : toggle.checked}">Text</h3>

CSS:

.primary-color {
    color: red; // you should use theming to access the theme's primary color
}