我在我的项目中使用Angular Material。我希望根据变量动态设置按钮类型。我尝试过以下方法:
export class ButtonComponent {
type: 'simple' | 'raised' | 'stroked' | 'flat' | 'icon' | 'fab' | 'mini-fab' = 'simple";
}
在HTML中
<button [mat-button]="type === 'simple'" [mat-raised-button]="type === 'raised'">
Text goes here
</button>
但是我遇到了以下错误:
无法绑定'mat-button',因为它不是'button'的已知属性
虽然我在我的module.ts中导入了MatButtonModule。
感谢您的时间,提前感谢您的帮助。
<button>
。因为如果DOM中已经有一个没有应用指令的按钮,而你后来再应用指令,它只会成为一个属性(指令中的代码不会被执行)。所以用**ngIf
包裹按钮,并将按钮放在其中。 - undefined