ngClass Angular 4,里面有函数

时间:2018-05-07 21:46:10

标签: html css angular

我正在尝试这样做它正在工作,但它只采用文本的颜色,而不是背景。

这是我的代码。

<div class="costs-block" [ngClass]="{'positive' : Difference < 0}">
  {{Difference | moneyFormat}}
</div>

$row-background-color: white;

.positive {
    background-color: red;
    color:white;
  }
.costs-block {
    @extend %common-block;
    @include center();
    @include justify-content(flex-end);
    margin-left: 10px;
    padding-right: 5px;
    width: 150px;
  }
%common-block {
  @extend .vp-row;
  background-color: $row-background-color;
  margin-top: 1px;
  margin-bottom: 1px;
  min-height: $content-height;
  border: solid thin $border-color;
  border-radius: 3px;
}

2 个答案:

答案 0 :(得分:1)

这样的事情:

<div class="costs-block" [ngClass]="Difference < 0 ? 'positive' : 'regular'">
    {{Difference | moneyFormat}}
</div>


    $row-background-color: white;

    .positive {
        background-color: red;
        color:white;
      }

    .regular{
        background-color: $row-background-color;
    }

    .costs-block {
        @extend %common-block;
        @include center();
        @include justify-content(flex-end);
        margin-left: 10px;
        padding-right: 5px;
        width: 150px;
      }

    %common-block {
      @extend .vp-row;
      margin-top: 1px;
      margin-bottom: 1px;
      min-height: $content-height;
      border: solid thin $border-color;
      border-radius: 3px;
    }

答案 1 :(得分:0)

试试这个

.positive {
background-color: red !important;
color: white;