1

I want to change a material mat-mini-fab button's color the when button is clicked.

My attempt is like below. But doesn't work.

<button mat-mini-fab color="primary" #btn>Btn</button>

@ViewChild('btn') btn: ElementRef;
clicked() {
    this.btn.nativeElement.style.backgroundColor = '#5789D8';
    this.btn.nativeElement.style.color = '#FFFFFF';
}
1
  • thank you mr. Ron to fix my question. Commented Apr 17, 2018 at 9:00

1 Answer 1

5

You can use [ngClass] to dynamically toggle a css class on click

<button [ngClass]="{'test': newColor}" (click)="toggleColor()" mat-fab>Primary</button>

Demo

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much. This is what I wanted to do.

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.