我想根据从网络服务获得的数据有条件地为一些标签着色。 Web 服务工作正常,数据被保存到数组 b。
例如, 如果标签包含“蓝色”,则将其涂成蓝色, 如果标签包含“红色”,则将其涂成红色 ETC。 我最多有 6 个条件。
<div class="centered">
<h2>List of labels </h2>
<label *ngFor="let a of b">
{{a.x}}
</label>
</div>
最佳答案
你需要的是ngStyle
。
<div class="centered">
<h2>List of labels </h2>
<label *ngFor="let a of b" [ngStyle]="{color: a.color}">
{{a.x}}
</label>
</div>
或者要求您的服务器提供类名并使用[ngClass]
关于css - Angular - 使用正则表达式和 css 使用 ngIf 和 ngFor 条件格式化标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54827535/