小编Zey*_*Aql的帖子

Angular Material 动态绑定按钮类型

我在我的项目中使用 Angular Material。我想根据变量动态设置按钮类型。我尝试了类似以下的操作:

export class ButtonComponent {
  type: 'simple' | 'raised' | 'stroked' | 'flat' | 'icon' | 'fab' | 'mini-fab' = 'simple";
}
Run Code Online (Sandbox Code Playgroud)

在 HTML 中

<button [mat-button]="type === 'simple'" [mat-raised-button]="type === 'raised'">
  Text goes here 
</button>
Run Code Online (Sandbox Code Playgroud)

但我收到以下错误:

无法绑定到“mat-button”,因为它不是“button”的已知属性

虽然我已经在我的 module.ts 中导入了 MatButtonModule

感谢您抽出宝贵的时间,并提前感谢大家。

button angular-material angular

5
推荐指数
1
解决办法
4071
查看次数

标签 统计

angular ×1

angular-material ×1

button ×1