角材质2单击时更改按钮颜色 [英] angular material2 change button color when clicked
本文介绍了角材质2单击时更改按钮颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在单击按钮时更改材质垫-迷你晶圆厂按钮的颜色.
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';
}
推荐答案
您可以使用[ngClass]
在点击时动态切换CSS类
You can use [ngClass]
to dynamically toggle a css class on click
<button [ngClass]="{'test': newColor}" (click)="toggleColor()" mat-fab>Primary</button>
这篇关于角材质2单击时更改按钮颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文