我在我的项目中使用 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
感谢您抽出宝贵的时间,并提前感谢大家。