Paco Zevallos
Paco Zevallos

Reputation: 2275

Change text style with mat-slide-toggle

How can I change the style of a text using Ang-Material-2's mat-slide-toggle?

enter image description here

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

Upvotes: 1

Views: 4849

Answers (1)

G. Tranter
G. Tranter

Reputation: 17908

Bind a class or style property to the <h3> element based on the toggle's state:

<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
}

Upvotes: 2

Related Questions