![](/img/trans.png)
[英]Angular 4 Material - mat-button style not being applied in mat-dialog component
[英]how to style a selected mat-button in an angular application
我有一个 Angular 应用程序,用户可以在其中选择多个按钮,按下按钮时将显示另一个组件。 组件取决于用户的选择。 我试图实现的一件事是按钮的样式,以明确选择了哪个选项。
<div fxLayout="row" fxLayoutAlign="space-between center" fxFill>
<div *ngFor="let button of buttons">
<button
mat-stroked-button
*ngIf="button.type === 'button'"
(click)="buttonPressed()"
ngxScrollTo
>
{{ button.text }}
</button>
</div>
<div fxLayout="row" fxLayoutAlign="space-between center">
<div *ngIf="item.hasSomeProperty | isTypeButton">
<button mat-mini-fab (click)="buttonPressed()">
<mat-icon>close</mat-icon>
</button>
</div>
</div>
任何帮助将非常感激。
<div *ngFor="let button of buttons">
<button
mat-stroked-button
*ngIf="button.type === 'button'"
[ngClass]="{'disabledButton': !button.selected}"
(click)="buttonPressed(button)"
ngxScrollTo
>
{{ button.text }}
</button>
</div>
假设您的按钮模型包含“selected”属性(或者您有一些其他模型存储实际单击哪个按钮的信息):
buttonPressed(button: Button) {
// Mark only button as selected
this.buttons.forEach(b => b.selected = b === button);
}
当然,在 css 中添加一些类:
.disabledButton {
opacity: 0.75;
}
注意 - 从我的头顶写这个(因为没有提供 stackblitz)所以可能需要一些调整。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.