使用* ngFor时如何仅将类设置为特定元素?

时间:2018-05-14 11:48:55

标签: javascript css angular typescript angular5

我使用*ngFor列出表格数据:*ngFor="let record of records", 我希望根据某些条件将自定义css类设置为record,例如: if record.name === something。这可能吗?

3 个答案:

答案 0 :(得分:2)

是的,您在[ngClass]上实现了这一目标,例如:

<div [ngClass]="{'record': record.name === 'something' }" *ngFor="let record of records">

答案 1 :(得分:0)

你可以这样试试:

  <ul class="r " *ngFor="let posto of posti">
    <li [ngClass]="posto.id === something ? NewClass : oldclass" >
     {{Something.id}} 
    </li>
  </ul>

答案 2 :(得分:0)

row_stats = dataframe
                 .withColumn("exploded" , explode(col("products")))
                 .withColumn("score", col("exploded").getItem(target_field))
                 .where(col("score").isNotNull())
                 .select(mean_(col("score")).alias("mean"),stddev_(col("score")).alias("stddev")).first()

mean = 0
std = 0
if row_stats is not None:
    print "row_stats.mean"
    print row_stats.mean
    mean = Decimal(float(row_stats.mean))
    std = Decimal(float(row_stats.stddev))