我看过类似的问题,但不能理解我正在寻找的解决方案。
所以基本上我有这段代码:
<div class="attendees-list__item-order-status course-details-attendees text text-cooler-grey align-self-center pl-3"
[ngClass]="
heading === 'Abrechenbare Buchungen' ? 'col-md-4' : ' col-md-3'
"
>
{{ attendee?.lastName }}, {{ attendee?.firstName }}
</div>我想修改和添加一个额外的声明。逻辑将是if (heading === 'Abrechenbare Buchungen'或if heading === 'Kürzlich abgerechnete Buchungen')和attendee?.orderStatus == 'CANCELLED',那么它应该将'text--line-through'类添加到col-md-3和col-md-4中。
我尝试了"||",就像我在其他类似问题中看到的那样,但找不到一个有效的解决方案,很可能是我写的语法不正确。
发布于 2019-09-17 22:30:04
使用这样的函数会很好,而不是把HTML搞得乱七八糟
<input type="text" [class]="getAgeTextColor(form.get('ActiveAge').value)" class="form-control-plaintext" [ngClass]="{'form-control-plaintext': true}" formControlName="ActiveAge">
getAgeTextColor(ActiveAge){
if(ActiveAge != null){
const months = ActiveAge.split(' ')[0];
if(months >= 24){
return 'text-green';
}else if(months > 12 && months < 24){
return 'text-yellow';
}else if(months <= 12){
return 'text-red';
}
}else{
return '';
}
}https://stackoverflow.com/questions/57975785
复制相似问题