大家好,我面临着一个问题,即在某些情况下机器人会应用 Angular 材质按钮的颜色,就像这样:
html:
<mat-card>
<mat-spinner *ngIf="isLoading"></mat-spinner>
<form [formGroup]="form" (submit)="onLogin()" *ngIf="!isLoading">
<mat-form-field>
<input matInput type="email" formControlName="email" placeholder="Email">
<mat-error *ngIf="form.get('email').invalid">Please enter a valid email.</mat-error>
</mat-form-field>
<mat-form-field>
<input matInput type="password" formControlName="password" placeholder="Password">
<mat-error *ngIf="form.get('password').invalid">Please enter a valid password.</mat-error>
</mat-form-field>
<mat-action-row>
<!-- NOT COLORED-->
<button mat-raised-button type="submit" color="warn">Login</button>
</mat-action-row>
</form>
<!-- COLORED-->
<button mat-raised-button type="submit" color="warn">Login</button>
</mat-card>
如您所见,两个按钮都有相同的代码,但其中一个按钮应用了颜色,而另一个则没有,我想在表单中使用该颜色...有什么解决方案吗?
我在 mat-select 和 mat-options 组件上也遇到了类似的问题。我知道这篇文章已经过时了,但这仍然是一个常见问题。有时,当您向材质组件添加样式时,它不起作用。
对我来说,我设法通过将与材质相关的样式移动到全局样式表来使其工作。这似乎始终有效。
this.form = this.fb.group({
email: ['', [Validators.required]],
password: ['', [Validators.required]]
});
在 compponent.ts 文件中