html - 如何使用 [ngClass] 或 customClass 更改标签集导航丸背景颜色

标签 html css angular6 ng-class

我正在使用 angular-7, 我想根据验证更改选项卡的颜色,我在检查时间表是否有效的地方添加了 customClass,如果它无效,我想将导航丸颜色更改为红色,否则正常

我试过在下面写代码但是没有用 你能帮我解决这个问题吗?


<div class="col">
     <tabset type="pills">
       <tab [heading]="strings.timesheetHeading"
          [customClass]="isTimesheetFormInvalid() ? 'invalid-timesheet-expense-tab' : ''">
          <pace-timesheet [model]="model.timesheetEntries" [parentForm]="timesheetFormChildren"></pace-timesheet>
        </tab>

        <tab [heading]="strings.expensesHeading"
                     [customClass]="isExpenseFormInvalid() ? 'invalid-timesheet-expense-tab' : ''">
              <pace-expenses [model]="model" [parentForm]="expensesFormChildren"></pace-expenses>
        </tab>
     </tabset>
</div>


CSS:

  .nav-pills > li.tab.invalid-timesheet-expense-tab.active > a,
  .nav-pills > li.tab.invalid-timesheet-expense-tab.active > a:hover,
  .nav-pills > li.tab.invalid-timesheet-expense-tab.active > a:focus {
    background-color: $common-color-error-red;

    heading {
      color: $common-color-white;
    }
  }

  .nav-pills > li.tab.invalid-timesheet-expense-tab > a,
  .nav-pills > li.tab.invalid-timesheet-expense-tab > a:hover,
  .nav-pills > li.tab.invalid-timesheet-expense-tab > a:focus {

    heading {
      color: $common-color-error-red;
    }
  }

最佳答案

<input type="text" class="form-control-plaintext" [ngClass]="{'bg-red': isTimesheetFormInvalid == true,'bg-green': isTimesheetFormInvalid == false}" formControlName="test">

使用 ngClass 添加条件类并根据您的要求添加条件我在使用 ngb-tabset 之前做了同样的事情。

希望对您有所帮助。

关于html - 如何使用 [ngClass] 或 customClass 更改标签集导航丸背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57972128/

相关文章:

javascript - Safari 中滚动不稳定

css - 如何修复我的 css 代码以便填充我的网格行?

angular - routerLink 在 Angular 6 中不起作用

angular - 错误 : Local workspace file ('angular.json' ) could not be found when upgraded to Angular 6

css - 如何将 mat-h​​orizo​​ntal-stepper 保持在页面中心

java - 从 Java 检索在网页上动态呈现的 SVG

javascript - 从窗口将值传递给 iframe

css - jQuery 是否支持将 CSS 应用于新创建的元素?

html - 响应式导航栏在调整大小时不显示所有选项

html - wordpress 中的简单站点页脚