Angular 在mat单元中应用ngclass获取错误角度8
我试图使用ngclass为我的条件为下面的html代码应用css,但它显示了错误 我想使用两个类,即colorRed和colorOrange 这是我的两个类(CSS) 这是条件Angular 在mat单元中应用ngclass获取错误角度8,angular,angular8,ng-class,Angular,Angular8,Ng Class,我试图使用ngclass为我的条件为下面的html代码应用css,但它显示了错误 我想使用两个类,即colorRed和colorOrange 这是我的两个类(CSS) 这是条件 如果百分比>=5%和=10%,则需要显示红色 这是我的html <ng-container matColumnDef="salaryIncrease"> <th mat-header-cell *matHeaderCellDef mat-sort-header> </th&
<ng-container matColumnDef="salaryIncrease">
<th mat-header-cell *matHeaderCellDef mat-sort-header> </th>
<td mat-cell [ngClass]="{'colorRed': element.salaryIncrease>= 5% }" *matCellDef="let element" > {{element.salaryIncreas| currency:'':''}}
</td>
</ng-container>
{{element.salaryIncreas |货币:'':'}
由于在比较过程中使用了%symbol,而%symbol无法用于比较,因此出现模板分析错误。只需比较百分比的值
同样,在标准方案中,仅存储百分比值的值符号仅在需要时添加
为你树立榜样
您遇到了什么错误?@NicholasK错误:模板分析错误:
元素。salaryIncrease>=5%
这不起作用。相比之下,您不应该使用%
——它在JS中不是运算符。
<ng-container matColumnDef="salaryIncrease">
<th mat-header-cell *matHeaderCellDef mat-sort-header> </th>
<td mat-cell [ngClass]="{'colorRed': element.salaryIncrease>= 5% }" *matCellDef="let element" > {{element.salaryIncreas| currency:'':''}}
</td>
</ng-container>