有角材质按钮不变色

问题描述 投票:0回答:3

大家好,我面临着一个问题,即在某些情况下机器人会应用 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>

结果: enter image description here

如您所见,两个按钮都有相同的代码,但其中一个按钮应用了颜色,而另一个则没有,我想在表单中使用该颜色...有什么解决方案吗?

html css angular angular-material
3个回答
0
投票

我在 mat-select 和 mat-options 组件上也遇到了类似的问题。我知道这篇文章已经过时了,但这仍然是一个常见问题。有时,当您向材质组件添加样式时,它不起作用。

对我来说,我设法通过将与材质相关的样式移动到全局样式表来使其工作。这似乎始终有效。


0
投票
这个.form------ 没有这样的问题,我没有抓住洛斯坎比奥斯。 Aun sigo con el Problema 10 2024


-5
投票
通过添加解决问题:

this.form = this.fb.group({ email: ['', [Validators.required]], password: ['', [Validators.required]] });

在 compponent.ts 文件中

© www.soinside.com 2019 - 2024. All rights reserved.