【发布时间】:2019-02-01 10:48:32
【问题描述】:
我有一个材质按钮 mat-stroked-button 如下:
<button mat-stroked-button color="accent" class="mat-login-header">Login</button>
如果用户使用较小的屏幕尺寸或分辨率(例如移动屏幕),我需要按钮将其类型更改为 mat-button,所以在组件构造函数中我正在尝试:
constructor() {
if(document.body.clientWidth < 600) {
//how to change the button from mat-stroked-button to mat-button?
}
}
如果文档宽度小于 600,如何将其更改为 mat-button,否则保持 mat-stroked-button
【问题讨论】:
-
如何创建两个按钮块并使用 *ngIf 基于变量(例如 smallUI)更改哪个按钮可见?
-
我的第一个猜测是做
[attr.mat-stroked-button]="condition"不幸的是它似乎不起作用。所以我建议你使用@hamilton.lima 的解决方案。 -
@Ploppy 那是因为
mat-stroked-button被声明为指令。