2

I have a button toggle group. The functionality is that when I click a particular item, the background color should be changed. When I toggle one of the buttons, the newly selected button's color should change and the old one should return back to the default background color. Here is my code:

HTML

<mat-button-toggle-group name="fontStyle" aria-label="Font Style" vertical >
  <mat-button-toggle value="bold" (click)="changeColor()" mat-button-toggle [style.background-color]="color">Bold</mat-button-toggle>
  <mat-button-toggle value="italic" (click)="changeColor()" mat-button-toggle [style.background-color]="color">Italic</mat-button-toggle>
  <mat-button-toggle value="underline"(click)="changeColor()" mat-button-toggle [style.background-color]="color">Underline</mat-button-toggle>
</mat-button-toggle-group>

TypeScript

export class ButtonToggleOverviewExample {
  color:string;

  changeColor(){ 
    this.color='green';
  }

}

The problem is that once a button is toggled it remains in the same color as clicked one.

3
  • each button has different color?? Commented Aug 24, 2018 at 5:01
  • No.All have same color. default color: white, on-click:green Commented Aug 24, 2018 at 5:45
  • check my solution. on demo Commented Aug 24, 2018 at 5:46

1 Answer 1

4

Try something like this:

DEMO

in style.css

.mat-button-toggle-checked{
  background-color: green;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.