angular - Angular Material - 如何在运行时更改按钮颜色
问题描述
我正在使用有角材料制作侧边栏菜单。我没有找到根据某些组件属性更改按钮颜色的方法。
我已经阅读了文档:https ://material.angular.io/components/button/overview
关于主题,它只说:
Buttons can be colored in terms of the current theme using the color property to set the background color to primary, accent, or warn.
这是我的代码:
<button
*ngFor="let link of links; let i = index"
mat-raised-button
color="primary"
(click)="selectedIndex = i"
[routerLink]="link.routerLink">
</button>
我什至不知道这是否可能,但我正在寻找这样的东西:
<button
*ngFor="let link of links; let i = index"
mat-raised-button
(click)="selectedIndex = i"
[color]="selectedIndex === i ? primary : warm"
[routerLink]="link.routerLink">
</button>
解决方案
很有可能,您需要将字符串文字传递给您的数据绑定[color]
[color]="selectedIndex === i ? 'primary' : 'warm'"
堆栈闪电战
https://stackblitz.com/edit/angular-npzkiu?embed=1&file=app/button-overview-example.html
推荐阅读
- php - jQuery中的nan查看多行值
- javascript - Laravel - 显示更多/更少按钮冲突
- linux - /proc/meminfo-inactive(file) 保持高位,并且不能被 drop_caches 回收
- bash - 提取电子邮件地址 Perl 脚本
- python - 如何在数据框中找到列的最小值的第一行
- android - 发布应用程序但出现错误 INSTALL_FAILED_UPDATE_INCOMPATIBLE
- html - 如何添加背景图像以填充此过渡中的文本?
- python - 超高精度高损耗?
- flutter - 颤振升级导致 getter 'fullObstruction' 没有为类 'ObstructingPreferredSizeWidget' 定义。错误
- scala - 将 Scala 类型参数向上转换为更通用特征的无样板方法